Changeset 249 for trunk/src/mesh/mesh.cc
- Timestamp:
- Mar 1, 2006, 1:07:04 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/mesh/mesh.cc
r246 r249 253 253 } 254 254 255 // 256 // total number bytes in mesh object 257 // 258 // NOTE: this doesn't count the id 259 // 260 int RpMesh3d::numBytes() 261 { 262 // numberOfNodes + all nodes + numberOfElements + numNodesInElement + nodes in elements 263 264 int nnie = (*m_elemList)[0].numNodes(); 265 int num = 3*sizeof(int) + m_numNodes*3*sizeof(int) + m_numElements*nnie*sizeof(int); 266 267 return num; 268 } 269 255 270 // serialization 256 271 char* 257 RpMesh3d::serialize() 258 { 259 return NULL; 272 RpMesh3d::serialize(int& numbytes) 273 { 274 int nbytes = this->numBytes(); 275 276 char * buf = new char[nbytes]; 277 if (buf != NULL) { 278 serialize(buf, nbytes); 279 numbytes = nbytes; 280 } 281 282 return buf; 260 283 } 261 284 … … 263 286 RpMesh3d::serialize(char* buf, int buflen) 264 287 { 288 int nbytes = this->numBytes(); 289 int nnie = (*m_elemList)[0].numNodes(); 290 int i; 291 292 if (buf == NULL || buflen < nbytes) { 293 RpAppendErr("RpMesh3d::serialize: invalid buffer"); 294 RpPrintErr(); 295 return RP_ERR_INVALID_ARRAY; 296 } 297 298 char *ptr = buf; 299 300 // write number of nodes 301 memcpy((void *)ptr, (void *)&m_numNodes, sizeof(int)); 302 ptr += sizeof(int); 303 304 // write all nodes 305 for (i=0; i < m_numNodes; i++) { 306 m_nodeList[i].serialize(ptr); 307 ptr += 3* sizeof(int); 308 } 309 310 // write number of elements 311 memcpy((void *)ptr, (void *)&m_numElements, sizeof(int)); 312 ptr += sizeof(int); 313 314 // write number of nodes in each element 315 memcpy((void *)ptr, (void *)&nnie, sizeof(int)); 316 ptr += sizeof(int); 317 318 // write all elements 319 for (i=0; i < m_numElements; i++) { 320 (*m_elemList)[i].serializeNodes(ptr); 321 ptr += nnie * sizeof(int); 322 } 265 323 266 324 return RP_SUCCESS; … … 270 328 RpMesh3d::deserialize(const char* buf) 271 329 { 330 int i; 331 332 if (buf == NULL) { 333 RpAppendErr("RpMesh3d::deserialize: null buffer"); 334 RpPrintErr(); 335 return RP_ERR_INVALID_ARRAY; 336 } 337 338 char *ptr = (char*)buf; 339 int nnie; 340 341 // read number of nodes 342 memcpy((void *)&m_numNodes, (void*)ptr, sizeof(int)); 343 ptr += sizeof(int); 344 345 // read all nodes 346 for (i=0; i < m_numNodes; i++) { 347 m_nodeList[i].deserialize(ptr); 348 m_nodeList[i].id(i); 349 ptr += 3* sizeof(int); 350 } 351 352 // read number of elements 353 memcpy((void *)&m_numElements, (void*)ptr, sizeof(int)); 354 ptr += sizeof(int); 355 356 // number of nodes in each element 357 memcpy((void *)&nnie, (void *)ptr, sizeof(int)); 358 ptr += sizeof(int); 359 360 // read all elements 361 for (i=0; i < m_numElements; i++) { 362 (*m_elemList)[i].deserializeNodes(ptr, nnie); 363 (*m_elemList)[i].id(i); 364 ptr += nnie * sizeof(int); 365 } 366 272 367 return RP_SUCCESS; 273 368 }
Note: See TracChangeset
for help on using the changeset viewer.