opennurbs_brep_io.cpp
Go to the documentation of this file.
00001 /* $NoKeywords: $ */
00002 /*
00003 //
00004 // Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
00005 // OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
00006 // McNeel & Associates.
00007 //
00008 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
00009 // ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
00010 // MERCHANTABILITY ARE HEREBY DISCLAIMED.
00011 //                              
00012 // For complete openNURBS copyright information see <http://www.opennurbs.org>.
00013 //
00015 */
00016 
00017 #include "pcl/surface/3rdparty/opennurbs/opennurbs.h"
00018 
00019 
00020 ON_BOOL32
00021 ON_BrepVertex::Write( ON_BinaryArchive& file ) const
00022 {
00023   ON_BOOL32 rc = file.WriteInt( m_vertex_index );
00024   if ( rc )
00025     rc = file.WritePoint( point );
00026   if ( rc )
00027     rc = file.WriteArray( m_ei );
00028   if ( rc )
00029     rc = file.WriteDouble( m_tolerance );
00030   return rc;
00031 }
00032 
00033 ON_BOOL32
00034 ON_BrepVertex::Read( ON_BinaryArchive& file )
00035 {
00036   ON_BOOL32 rc = file.ReadInt( &m_vertex_index );
00037   if ( rc )
00038     rc = file.ReadPoint( point );
00039   if ( rc )
00040     rc = file.ReadArray( m_ei );
00041   if ( rc )
00042     rc = file.ReadDouble( &m_tolerance );
00043   return rc;
00044 }
00045 
00046 ON_BOOL32 ON_BrepEdge::Write( ON_BinaryArchive& file ) const
00047 {
00048   ON_BOOL32 rc = file.WriteInt( m_edge_index );
00049   if (rc) rc = file.WriteInt( m_c3i );
00050   int i = ProxyCurveIsReversed() ? 1 : 0;
00051   if (rc) rc = file.WriteInt( i );
00052   if (rc) rc = file.WriteInterval( ProxyCurveDomain() );
00053   if (rc) rc = file.WriteInt( 2, m_vi );
00054   if (rc) rc = file.WriteArray( m_ti );
00055   if (rc) rc = file.WriteDouble( m_tolerance );
00056   if ( file.Archive3dmVersion() >= 3 )
00057   {
00058     // added in opennurbs version 200206180
00059     if (rc)
00060       rc = file.WriteInterval( Domain() );
00061   }
00062   return rc;
00063 }
00064 
00065 ON_BOOL32 ON_BrepEdge::Read( ON_BinaryArchive& file )
00066 {
00067   int bReversed = false;
00068   ON_Interval proxy_domain;
00069   ON_BOOL32 rc = file.ReadInt( &m_edge_index );
00070   if (rc) rc = file.ReadInt( &m_c3i );
00071   if (rc) rc = file.ReadInt( &bReversed );
00072   if (rc) rc = file.ReadInterval( proxy_domain );
00073   if (rc) rc = file.ReadInt( 2, m_vi );
00074   if (rc) rc = file.ReadArray( m_ti );
00075   if (rc) rc = file.ReadDouble( &m_tolerance );
00076   ON_Interval domain = proxy_domain;
00077   if (    file.Archive3dmVersion() >= 3 
00078        && file.ArchiveOpenNURBSVersion() >= 200206180 )
00079   {
00080     if (rc) 
00081     {
00082       rc = file.ReadInterval(domain);
00083       if ( !rc)
00084         domain = proxy_domain;
00085     }
00086   }
00087   SetProxyCurve( NULL, proxy_domain );
00088   if ( bReversed )
00089     ON_CurveProxy::Reverse();
00090   SetDomain(domain);
00091 
00092   return rc;
00093 }
00094 
00095 ON_BOOL32 ON_BrepTrim::Write( ON_BinaryArchive& file ) const
00096 {
00097   ON_3dPoint P(0.0,0.0,0.0);
00098   ON_BOOL32 rc = file.WriteInt( m_trim_index );
00099   int i;
00100   if ( rc )
00101     rc = file.WriteInt( m_c2i );
00102   if ( rc )
00103     rc = file.WriteInterval( ProxyCurveDomain() );
00104   if ( rc )
00105     rc = file.WriteInt( m_ei );
00106   if ( rc )
00107     rc = file.WriteInt( 2, m_vi );
00108   if ( rc )
00109     rc = file.WriteInt( m_bRev3d );
00110   i = m_type;
00111   if ( rc )
00112     rc = file.WriteInt( i );
00113   i = m_iso;
00114   if ( rc )
00115     rc = file.WriteInt( i );
00116   if ( rc )
00117     rc = file.WriteInt( m_li );
00118   if ( rc )
00119     rc = file.WriteDouble( 2, m_tolerance );
00120   if ( file.Archive3dmVersion() < 3 )
00121   {
00122     if ( rc )
00123       rc = file.WritePoint( P ); // m_P[0] );
00124     if ( rc )
00125       rc = file.WritePoint( P ); // m_P[1] );
00126   }
00127   else
00128   {
00129     // trim proxy curve information added in version 200206180
00130     if (rc )
00131       rc = file.WriteInterval( Domain() );
00132     unsigned char b[24];
00133     memset(b,0,sizeof(b));
00134     b[0] = ProxyCurveIsReversed() ? 1 : 0;
00135     if (rc)
00136       rc = file.WriteChar(8,b);
00137     b[0] = 0;
00138     if (rc)
00139       rc = file.WriteChar(24,b);
00140   }
00141   if ( rc )
00142     rc = file.WriteDouble( m__legacy_2d_tol );
00143   if ( rc )
00144     rc = file.WriteDouble( m__legacy_3d_tol );
00145   return rc;
00146 }
00147 
00148 ON_BOOL32 ON_BrepTrim::Read( ON_BinaryArchive& file )
00149 {
00150   ON_3dPoint P[2];
00151   int i;
00152   ON_BOOL32 rc = file.ReadInt( &m_trim_index );
00153   if ( rc )
00154     rc = file.ReadInt( &m_c2i );
00155   if ( rc )
00156   {
00157     ON_Interval d;
00158     rc = file.ReadInterval( d );
00159     if (rc)
00160     {
00161       SetProxyCurveDomain(d);
00162       SetDomain(d);
00163     }
00164   }
00165   if ( rc )
00166     rc = file.ReadInt( &m_ei );
00167   if ( rc )
00168     rc = file.ReadInt( 2, m_vi );
00169   if ( rc )
00170   {
00171     i = m_bRev3d;
00172     rc = file.ReadInt( &i );
00173     if (rc)
00174       m_bRev3d = (i!=0);
00175   }
00176 
00177   i = unknown;
00178   if ( rc )
00179     rc = file.ReadInt( &i );
00180   switch (i) {
00181   case unknown:
00182     m_type = unknown;
00183     break;
00184   case boundary:
00185     m_type = boundary;
00186     break;
00187   case mated:
00188     m_type = mated;
00189     break;
00190   case seam:
00191     m_type = seam;
00192     break;
00193   case singular:
00194     m_type = singular;
00195     break;
00196   }
00197 
00198   i = ON_Surface::not_iso;
00199   if ( rc )
00200     rc = file.ReadInt( &i );
00201   switch(i) {
00202   case ON_Surface::not_iso:
00203     m_iso = ON_Surface::not_iso;
00204     break;
00205   case ON_Surface::x_iso:
00206     m_iso = ON_Surface::x_iso;
00207     break;
00208   case ON_Surface::y_iso:
00209     m_iso = ON_Surface::y_iso;
00210     break;
00211   case ON_Surface::W_iso:
00212     m_iso = ON_Surface::W_iso;
00213     break;
00214   case ON_Surface::S_iso:
00215     m_iso = ON_Surface::S_iso;
00216     break;
00217   case ON_Surface::E_iso:
00218     m_iso = ON_Surface::E_iso;
00219     break;
00220   case ON_Surface::N_iso:
00221     m_iso = ON_Surface::N_iso;
00222     break;
00223   }
00224 
00225   if ( rc )
00226     rc = file.ReadInt( &m_li );
00227   if ( rc )
00228     rc = file.ReadDouble( 2, m_tolerance );
00229   if ( file.Archive3dmVersion() >= 3 && file.ArchiveOpenNURBSVersion() >= 200206180 )
00230   {
00231     // read trim proxy curve information added in version 200206180
00232     ON_Interval d = ProxyCurveDomain();
00233     if (rc )
00234     {
00235       rc = file.ReadInterval( d );
00236       if ( !rc )
00237         d = ProxyCurveDomain();
00238     }
00239     unsigned char b[24];
00240     memset(b,0,sizeof(b));
00241     bool bProxyCurveIsReversed = false;
00242     if (rc)
00243     {
00244       rc = file.ReadChar(8,b);
00245       if (rc && b[0] == 1 )
00246         bProxyCurveIsReversed = true;
00247     }
00248     if (rc)
00249       rc = file.ReadChar(24,b);
00250 
00251     if ( bProxyCurveIsReversed )
00252       ON_CurveProxy::Reverse();
00253     SetDomain(d);
00254   }
00255   else
00256   {
00257     if ( rc )
00258       rc = file.ReadPoint( P[0] ); //m_P[0] );
00259     if ( rc )
00260       rc = file.ReadPoint( P[1] ); //m_P[1] );
00261   }
00262   if ( rc )
00263     rc = file.ReadDouble( &m__legacy_2d_tol );
00264   if ( rc )
00265     rc = file.ReadDouble( &m__legacy_3d_tol );
00266   return rc;
00267 }
00268 
00269 ON_BOOL32 ON_BrepLoop::Write( ON_BinaryArchive& file ) const
00270 {
00271   int i;
00272   ON_BOOL32 rc = file.WriteInt( m_loop_index );
00273   if (rc)
00274     rc = file.WriteArray( m_ti );
00275   i = m_type;
00276   if (rc)
00277     rc = file.WriteInt( i );
00278   if (rc)
00279     rc = file.WriteInt( m_fi );
00280   return rc;
00281 }
00282 
00283 ON_BOOL32 ON_BrepLoop::Read( ON_BinaryArchive& file )
00284 {
00285   int i;
00286   ON_BOOL32 rc = file.ReadInt( & m_loop_index );
00287   if (rc)
00288     rc = file.ReadArray( m_ti );
00289 
00290   i = unknown;
00291   if (rc)
00292     rc = file.ReadInt( &i );
00293   switch(i) {
00294   case unknown:
00295     m_type = unknown;
00296     break;
00297   case outer:
00298     m_type = outer;
00299     break;
00300   case inner:
00301     m_type = inner;
00302     break;
00303   case slit:
00304     m_type = slit;
00305     break;
00306   }
00307 
00308   if (rc)
00309     rc = file.ReadInt( &m_fi );
00310   return rc;
00311 }
00312 
00313 ON_BOOL32 ON_BrepFace::Write( ON_BinaryArchive& file ) const
00314 {
00315   bool rc = file.WriteInt( m_face_index );
00316   if ( rc )
00317     rc = file.WriteArray( m_li );
00318   if ( rc )
00319     rc = file.WriteInt( m_si );
00320   if ( rc )
00321     rc = file.WriteInt( m_bRev );
00322   if ( rc )
00323     rc = file.WriteInt( m_face_material_channel );
00324   return rc;
00325 }
00326 
00327 ON_BOOL32 ON_BrepFace::Read( ON_BinaryArchive& file )
00328 {
00329   int i;
00330   bool rc = file.ReadInt( &m_face_index );
00331   if ( rc )
00332     rc = file.ReadArray( m_li );
00333   if ( rc )
00334     rc = file.ReadInt( &m_si );
00335   if ( rc )
00336   {
00337     i = m_bRev;
00338     rc = file.ReadInt( &i );
00339     if ( rc )
00340       m_bRev = (i!=0);
00341   }
00342   if ( rc )
00343   {
00344     rc = file.ReadInt( &m_face_material_channel );
00345     if ( m_face_material_channel < 0 )
00346       m_face_material_channel = 0;
00347   }
00348   return rc;
00349 }
00350 
00351 ON_BOOL32 ON_BrepVertexArray::Read( ON_BinaryArchive& file )
00352 {
00353   Empty();
00354   ON__UINT32 tcode = 0;
00355   ON__INT64 length_TCODE_ANONYMOUS_CHUNK = 0;
00356   int count = 0;
00357   int i;
00358   int major_version = 0;
00359   int minor_version = 0;
00360   bool rc = file.BeginRead3dmBigChunk( &tcode, &length_TCODE_ANONYMOUS_CHUNK );
00361   if (rc) {
00362     if (tcode != TCODE_ANONYMOUS_CHUNK)
00363       rc = false;
00364     if (rc) rc = file.Read3dmChunkVersion(&major_version,&minor_version);
00365     if (rc) {
00366       if ( major_version==1 ) {
00367         if (rc) rc = file.ReadInt(&count);
00368         SetCapacity(count);
00369         for ( i = 0; i < count && rc ; i++ ) {
00370           ON_BrepVertex& vertex = AppendNew();
00371           rc = vertex.Read(file)?true:false;
00372         }    
00373       }
00374       else {
00375         rc = 0;
00376       }
00377     }
00378     if ( !file.EndRead3dmChunk() )
00379       rc = false;
00380   }
00381   return rc;
00382 }
00383 
00384 ON_BOOL32 ON_BrepVertexArray::Write( ON_BinaryArchive& file ) const
00385 {
00386   int i;
00387   ON_BOOL32 rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
00388   if (rc) {
00389     rc = file.Write3dmChunkVersion(1,0);
00390     const int count = Count();
00391     if (rc) rc = file.WriteInt( count );
00392     for ( i = 0; rc && i < count; i++ ) {
00393       if (rc) rc = m_a[i].Write(file);
00394     }
00395     if ( !file.EndWrite3dmChunk() )
00396       rc = false;
00397   }
00398   return rc;
00399 }
00400 
00401 ON_BOOL32 ON_BrepEdgeArray::Read( ON_BinaryArchive& file )
00402 {
00403   Empty();
00404   ON__UINT32 tcode = 0;
00405   ON__INT64 length_TCODE_ANONYMOUS_CHUNK = 0;
00406   int count = 0;
00407   int i;
00408   int major_version = 0;
00409   int minor_version = 0;
00410   bool rc = file.BeginRead3dmBigChunk( &tcode, &length_TCODE_ANONYMOUS_CHUNK );
00411   if (rc) {
00412     if (tcode != TCODE_ANONYMOUS_CHUNK)
00413       rc = false;
00414     if (rc) rc = file.Read3dmChunkVersion(&major_version,&minor_version);
00415     if (rc) {
00416       if ( major_version==1 ) {
00417         if (rc) rc = file.ReadInt(&count);
00418         SetCapacity(count);
00419         for ( i = 0; i < count && rc ; i++ ) {
00420           ON_BrepEdge& edge = AppendNew();
00421           rc = edge.Read(file) ? true : false;
00422         }    
00423       }
00424       else {
00425         rc = 0;
00426       }
00427     }
00428     if ( !file.EndRead3dmChunk() )
00429       rc = false;
00430   }
00431   return rc;
00432 }
00433 
00434 ON_BOOL32 ON_BrepEdgeArray::Write( ON_BinaryArchive& file ) const
00435 {
00436   int i;
00437   ON_BOOL32 rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
00438   if (rc) {
00439     rc = file.Write3dmChunkVersion(1,0);
00440     const int count = Count();
00441     if (rc) rc = file.WriteInt( count );
00442     for ( i = 0; rc && i < count; i++ ) {
00443       if (rc) rc = m_a[i].Write(file);
00444     }
00445     if ( !file.EndWrite3dmChunk() )
00446       rc = false;
00447   }
00448   return rc;
00449 }
00450 
00451 ON_BOOL32 ON_BrepTrimArray::Read( ON_BinaryArchive& file )
00452 {
00453   Empty();
00454   ON__UINT32 tcode = 0;
00455   ON__INT64 length_TCODE_ANONYMOUS_CHUNK = 0;
00456   int count = 0;
00457   int i;
00458   int major_version = 0;
00459   int minor_version = 0;
00460   bool rc = file.BeginRead3dmBigChunk( &tcode, &length_TCODE_ANONYMOUS_CHUNK );
00461   if (rc) {
00462     if (tcode != TCODE_ANONYMOUS_CHUNK)
00463       rc = false;
00464     if (rc) rc = file.Read3dmChunkVersion(&major_version,&minor_version);
00465     if (rc) {
00466       if ( major_version==1 ) {
00467         if (rc) rc = file.ReadInt(&count);
00468         SetCapacity(count);
00469         for ( i = 0; i < count && rc ; i++ ) {
00470           ON_BrepTrim& trim = AppendNew();
00471           rc = trim.Read(file)?true:false;
00472         }    
00473       }
00474       else {
00475         rc = 0;
00476       }
00477     }
00478     if ( !file.EndRead3dmChunk() )
00479       rc = false;
00480   }
00481   return rc;
00482 }
00483 
00484 ON_BOOL32 ON_BrepTrimArray::Write( ON_BinaryArchive& file ) const
00485 {
00486   int i;
00487   ON_BOOL32 rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
00488   if (rc) {
00489     rc = file.Write3dmChunkVersion(1,0);
00490     const int count = Count();
00491     if (rc) rc = file.WriteInt( count );
00492     for ( i = 0; rc && i < count; i++ ) {
00493       if (rc) rc = m_a[i].Write(file);
00494     }
00495     if ( !file.EndWrite3dmChunk() )
00496       rc = false;
00497   }
00498   return rc;
00499 }
00500 
00501 ON_BOOL32 ON_BrepLoopArray::Read( ON_BinaryArchive& file )
00502 {
00503   Empty();
00504   ON__UINT32 tcode = 0;
00505   ON__INT64 length_TCODE_ANONYMOUS_CHUNK = 0;
00506   int count = 0;
00507   int i;
00508   int major_version = 0;
00509   int minor_version = 0;
00510   bool rc = file.BeginRead3dmBigChunk( &tcode, &length_TCODE_ANONYMOUS_CHUNK );
00511   if (rc) {
00512     if (tcode != TCODE_ANONYMOUS_CHUNK)
00513       rc = false;
00514     if (rc) rc = file.Read3dmChunkVersion(&major_version,&minor_version);
00515     if (rc) {
00516       if ( major_version==1 ) {
00517         if (rc) rc = file.ReadInt(&count);
00518         SetCapacity(count);
00519         for ( i = 0; i < count && rc ; i++ ) {
00520           ON_BrepLoop& loop = AppendNew();
00521           rc = loop.Read(file) ? true : false;
00522         }    
00523       }
00524       else {
00525         rc = 0;
00526       }
00527     }
00528     if ( !file.EndRead3dmChunk() )
00529       rc = false;
00530   }
00531   return rc;
00532 }
00533 
00534 ON_BOOL32 ON_BrepLoopArray::Write( ON_BinaryArchive& file ) const
00535 {
00536   int i;
00537   ON_BOOL32 rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
00538   if (rc) {
00539     rc = file.Write3dmChunkVersion(1,0);
00540     const int count = Count();
00541     if (rc) rc = file.WriteInt( count );
00542     for ( i = 0; rc && i < count; i++ ) {
00543       if (rc) rc = m_a[i].Write(file);
00544     }
00545     if ( !file.EndWrite3dmChunk() )
00546       rc = false;
00547   }
00548   return rc;
00549 }
00550 
00551 ON_BOOL32 ON_BrepFaceArray::Read( ON_BinaryArchive& file )
00552 {
00553   Empty();
00554   ON__UINT32 tcode = 0;
00555   ON__INT64 length_TCODE_ANONYMOUS_CHUNK = 0;
00556   int count = 0;
00557   int i;
00558   int major_version = 0;
00559   int minor_version = 0;
00560   bool rc = file.BeginRead3dmBigChunk( &tcode, &length_TCODE_ANONYMOUS_CHUNK );
00561   if (rc) {
00562     if (tcode != TCODE_ANONYMOUS_CHUNK)
00563       rc = false;
00564     if (rc) rc = file.Read3dmChunkVersion(&major_version,&minor_version);
00565     if (rc) {
00566       if ( major_version==1 ) 
00567       {
00568         if (rc) rc = file.ReadInt(&count);
00569         SetCapacity(count);
00570         for ( i = 0; i < count && rc ; i++ ) 
00571         {
00572           ON_BrepFace& face = AppendNew();
00573           rc = face.Read(file)?true:false;
00574         }    
00575 
00576         if ( minor_version >= 1 )
00577         {
00578           // chunk version 1.1 and later has face uuids
00579           for ( i = 0; i < count && rc; i++ )
00580           {
00581             rc = file.ReadUuid( m_a[i].m_face_uuid );
00582           }
00583         }
00584       }
00585       else 
00586       {
00587         rc = 0;
00588       }
00589     }
00590     if ( !file.EndRead3dmChunk() )
00591       rc = false;
00592   }
00593   return rc;
00594 }
00595 
00596 ON_BOOL32 ON_BrepFaceArray::Write( ON_BinaryArchive& file ) const
00597 {
00598   int i;
00599   ON_BOOL32 rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
00600   if (rc) 
00601   {
00602     rc = file.Write3dmChunkVersion(1,1); // 1.1 added m_face_uuid
00603 
00604     // chunk version 1.0 and later
00605     const int count = Count();
00606     if (rc) rc = file.WriteInt( count );
00607     for ( i = 0; rc && i < count; i++ ) 
00608     {
00609       if (rc) rc = m_a[i].Write(file);
00610     }
00611 
00612     // chunk version 1.1 and later
00613     for ( i = 0; rc && i < count; i++ )
00614     {
00615       rc = file.WriteUuid( m_a[i].m_face_uuid );
00616     }
00617 
00618     if ( !file.EndWrite3dmChunk() )
00619       rc = false;
00620   }
00621   return rc;
00622 }
00623 
00624 
00625 ON_BOOL32 ON_Brep::Write( ON_BinaryArchive& file ) const
00626 {
00627   const ON_Brep* brep = this;
00628   ON_Brep* v2brep = 0;
00629 
00630   //ON_BOOL32 rc = file.Write3dmChunkVersion(3,0); // serialization version
00631   //ON_BOOL32 rc = file.Write3dmChunkVersion(3,1); // added meshes
00632   ON_BOOL32 rc = file.Write3dmChunkVersion(3,2); // added m_is_solid
00633 
00634   // 2d curves
00635   if (rc) rc = brep->m_C2.Write(file);
00636 
00637   // 3d curves
00638   if (rc) rc = brep->m_C3.Write(file);
00639 
00640   // untrimmed surfaces
00641   if (rc) rc = brep->m_S.Write(file);
00642 
00643   // vertices
00644   if (rc) rc = brep->m_V.Write(file);
00645 
00646   // edges
00647   if (rc) rc = brep->m_E.Write(file);
00648 
00649   // trims
00650   if (rc) rc = brep->m_T.Write(file);
00651 
00652   // loops
00653   if (rc) rc = brep->m_L.Write(file);
00654 
00655   // faces
00656   if (rc) rc = brep->m_F.Write(file);
00657 
00658   // bounding box
00659   if (rc) rc = file.WritePoint( brep->m_bbox.m_min );
00660   if (rc) rc = file.WritePoint( brep->m_bbox.m_max );
00661 
00662   // end of chunk version 3.0
00663 
00664   if (rc)
00665   {
00666     // added for chunk version 3.1
00667     const int face_count = brep->m_F.Count();
00668     int fi;
00669     unsigned char b;
00670 
00671     // write render meshes
00672     rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
00673     if ( rc )
00674     {
00675       for ( fi = 0; rc && fi < face_count; fi++ ) {
00676         const ON_Mesh* mesh = file.Save3dmRenderMeshes() ? brep->m_F[fi].m_render_mesh : 0;
00677         b = mesh ? 1 : 0;
00678         rc = file.WriteChar(b);
00679         if (rc && mesh) {
00680           rc = file.WriteObject(*mesh);
00681         }
00682       }
00683       if ( !file.EndWrite3dmChunk() )
00684       {
00685         rc = false;
00686       }
00687     }
00688 
00689     // write analysis meshes
00690     if (rc) rc = file.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 0 );
00691     if ( rc )
00692     {
00693       for ( fi = 0; rc && fi < face_count; fi++ ) {
00694         const ON_Mesh* mesh = file.Save3dmAnalysisMeshes() ? brep->m_F[fi].m_analysis_mesh : 0;
00695         b = mesh ? 1 : 0;
00696         rc = file.WriteChar(b);
00697         if (rc && mesh) {
00698           rc = file.WriteObject(*mesh);
00699         }
00700       }
00701       if ( !file.EndWrite3dmChunk() )
00702         rc = false;
00703     }
00704 
00705   }
00706   // end of chunk version 3.1
00707 
00708   if (rc)
00709   {
00710     // use value of "this" m_is_solid to avoid expensive 
00711     // calculation on the v2brep
00712     if ( !file.WriteInt( m_is_solid ) )
00713       rc = false;
00714   }
00715   // end of chunk version 3.2
00716 
00717   if ( 0 != v2brep )
00718     delete v2brep;
00719 
00720   return rc;
00721 }
00722 
00723 static
00724 void ReadFillInMissingBoxes( ON_Brep& brep )
00725 {
00726   // older files did not save bounding box information
00727   int ti, li, lti, trim_count, loop_count;
00728   const ON_Curve* c2;
00729   trim_count = brep.m_T.Count();
00730   loop_count = brep.m_L.Count();
00731   for ( ti = 0; ti < trim_count; ti++ )
00732   {
00733     ON_BrepTrim& trim = brep.m_T[ti];
00734     if ( !trim.m_pbox.IsValid() ) 
00735     {
00736       c2 = trim.TrimCurveOf();
00737       if ( c2 )
00738         trim.m_pbox = c2->BoundingBox();
00739     }
00740   }
00741 
00742   for ( li = 0; li < loop_count; li++ )
00743   {
00744     ON_BrepLoop& loop = brep.m_L[li];
00745     if ( !loop.m_pbox.IsValid() ) 
00746     {
00747       for ( lti = 0; lti < loop.m_ti.Count(); lti++ )
00748       {
00749         ti = loop.m_ti[lti];
00750         if ( ti >= 0 && ti < trim_count )
00751           loop.m_pbox.Union( brep.m_T[ti].m_pbox );
00752       }
00753     }
00754   }
00755 }
00756 
00757 ON_BOOL32 ON_Brep::Read( ON_BinaryArchive& file )
00758 {
00759   int i;
00760   int C2_count = 0;
00761   int C3_count = 0;
00762   int S_count = 0;
00763   int major_version = 0;
00764   int minor_version = 0;
00765   ON_BOOL32 rc = file.Read3dmChunkVersion( &major_version, &minor_version );
00766   if ( rc && major_version == 2 ) 
00767   {
00768     rc = ReadOld200(file,minor_version); // legacy trimmed face
00769   }
00770   else if ( rc && major_version == 3 ) 
00771   {
00772     // 2d curves
00773     if (rc) 
00774       rc = m_C2.Read(file);
00775     C2_count = m_C2.Count();
00776 
00777     // 3d curves
00778     if (rc) 
00779       rc = m_C3.Read(file);
00780     C3_count = m_C3.Count();
00781 
00782     // untrimmed surfaces
00783     if (rc) 
00784       rc = m_S.Read(file);
00785     S_count = m_S.Count();
00786 
00787     // vertices
00788     if (rc) 
00789       rc = m_V.Read(file);
00790 
00791     // edges
00792     if (rc) 
00793     {
00794       rc = m_E.Read(file);
00795       if (rc) {
00796         for ( i = 0; i < m_E.Count(); i++ ) {
00797           ON_BrepEdge& e = m_E[i];
00798           e.m_brep = this;
00799           if ( e.m_c3i >= 0 && e.m_c3i < C3_count )
00800           {
00801             bool bProxyCurveIsReversed = e.ProxyCurveIsReversed();
00802             ON_Interval pdom = e.ProxyCurveDomain();
00803             ON_Interval edom = e.Domain();
00804             e.SetProxyCurve( m_C3[e.m_c3i], pdom );
00805             if ( bProxyCurveIsReversed )
00806               e.ON_CurveProxy::Reverse();
00807             e.SetDomain(edom);
00808           }
00809         }
00810       }
00811     }
00812 
00813     // trims
00814     if (rc) 
00815     {
00816       rc = m_T.Read(file);
00817       if (rc) {
00818         for ( i = 0; i < m_T.Count(); i++ ) {
00819           ON_BrepTrim& trim = m_T[i];
00820           trim.m_brep = this;
00821           if ( trim.m_c2i >= 0 && trim.m_c2i < C2_count )
00822           {
00823             bool bProxyCurveIsReversed = trim.ProxyCurveIsReversed();
00824             ON_Interval pdom = trim.ProxyCurveDomain();
00825             ON_Interval tdom = trim.Domain();
00826             trim.SetProxyCurve( m_C2[trim.m_c2i], pdom );
00827             if ( bProxyCurveIsReversed )
00828               trim.ON_CurveProxy::Reverse();
00829             trim.SetDomain(tdom);
00830           }
00831         }
00832       }
00833     }
00834 
00835     // loops
00836     if (rc) 
00837     {
00838       rc = m_L.Read(file);
00839       if ( rc )
00840       {
00841         for ( i = 0; i < m_L.Count(); i++ ) 
00842         {
00843           m_L[i].m_brep = this;
00844         }
00845       }
00846     }
00847 
00848     // faces
00849     if (rc) 
00850     {
00851       rc = m_F.Read(file);
00852       if (rc) {
00853         for ( i = 0; i < m_F.Count(); i++ ) {
00854           ON_BrepFace& f = m_F[i];
00855           f.m_brep = this;
00856           if ( f.m_si >= 0 && f.m_si < S_count )
00857             f.SetProxySurface(m_S[f.m_si]);
00858         }
00859       }
00860     }
00861 
00862     // bounding box
00863     if (rc) 
00864       rc = file.ReadPoint( m_bbox.m_min );
00865     if (rc) 
00866       rc = file.ReadPoint( m_bbox.m_max );
00867 
00868     // fill in missing information
00869     ReadFillInMissingBoxes(*this);
00870 
00871     // end of chunk version 3.0
00872 
00873     if (rc && minor_version >= 1 )
00874     {
00875       // added for chunk version 3.1
00876 
00877       ON_Object* obj;
00878       ON__UINT32 tcode = 0;
00879       ON__INT64 length_TCODE_ANONYMOUS_CHUNK = 0;
00880       int fi;
00881       unsigned char b;
00882 
00883       const int face_count = m_F.Count();
00884 
00885       // read render meshes
00886       tcode = 0;
00887       length_TCODE_ANONYMOUS_CHUNK = 0;
00888       rc = file.BeginRead3dmBigChunk( &tcode, &length_TCODE_ANONYMOUS_CHUNK );
00889       if ( rc )
00890       {
00891         if ( tcode != TCODE_ANONYMOUS_CHUNK )
00892           rc = false;
00893         else
00894         {
00895           for ( fi = 0; rc && fi < face_count; fi++ ) 
00896           {
00897             rc = file.ReadChar(&b);
00898             if (rc && b) 
00899             {
00900               obj = 0;
00901               rc = file.ReadObject(&obj);
00902               if ( 0 != obj )
00903               {
00904                 m_F[fi].m_render_mesh = ON_Mesh::Cast(obj);
00905                 if ( !m_F[fi].m_render_mesh )
00906                   delete obj;
00907               }
00908             }
00909           }
00910         }
00911         if ( !file.EndRead3dmChunk() )
00912           rc = false;
00913       }
00914 
00915       if (rc)
00916       {
00917         // read analysis meshes
00918         tcode = 0;
00919         length_TCODE_ANONYMOUS_CHUNK = 0;
00920         rc = file.BeginRead3dmBigChunk( &tcode, &length_TCODE_ANONYMOUS_CHUNK );
00921         if ( rc )
00922         {
00923           if ( tcode != TCODE_ANONYMOUS_CHUNK )
00924             rc = false;
00925           else
00926           {
00927             for ( fi = 0; rc && fi < face_count; fi++ ) 
00928             {
00929               rc = file.ReadChar(&b);
00930               if (rc && b) 
00931               {
00932                 rc = file.ReadObject(&obj);
00933                 m_F[fi].m_analysis_mesh = ON_Mesh::Cast(obj);
00934                 if ( !m_F[fi].m_analysis_mesh )
00935                   delete obj;
00936               }
00937             }
00938           }
00939           if ( !file.EndRead3dmChunk() )
00940             rc = false;
00941         }
00942       }
00943     }
00944 
00945     if ( rc && minor_version >= 2 )
00946     {
00947       rc =  file.ReadInt( &m_is_solid );
00948       if ( m_is_solid < 0 || m_is_solid >= 3 )
00949         m_is_solid = 0;
00950     }
00951   }
00952 
00953   if ( file.ArchiveOpenNURBSVersion() < 20021002 )
00954   {
00955     m_is_solid = 0;
00956   }
00957 
00958   return rc;
00959 }
00960 
00961 
00962 bool ON_Brep::ReadOld200( ON_BinaryArchive& file, int minor_version )
00963 {
00964   bool rc = true;
00965 
00966   // read legacy trimmed surface collection from Rhino 2.0
00967 
00968   int face_count = 0;
00969   int edge_count = 0;
00970   int loop_count = 0;
00971   int trim_count = 0;
00972   int outer_flag = 0;
00973 
00974   ON_BoundingBox bnd_2d_bbox;
00975   int i, fi, fbi, fbcnt, bti, btcnt, twin_index;
00976   int ftype_flag, btype_flag, gcon_flag, mono_flag;
00977   char b;
00978 
00979   if (rc) rc = file.ReadInt( &face_count );
00980   if (rc) rc = file.ReadInt( &edge_count );
00981   if (rc) rc = file.ReadInt( &loop_count );
00982   if (rc) rc = file.ReadInt( &trim_count );
00983 
00984   if ( face_count < 1 || edge_count < 1 || loop_count < 1 || trim_count < 1 )
00985     rc = false;
00986 
00987   if (rc) rc = file.ReadInt( &outer_flag );
00988   if (rc) rc = file.ReadPoint( m_bbox.m_min );
00989   if (rc) rc = file.ReadPoint( m_bbox.m_max );
00990 
00991   // 2d curves
00992   m_C2.Reserve(trim_count);
00993   for ( i = 0; rc && i < trim_count; i++ ) {
00994     ON_PolyCurve* curve = new ON_PolyCurve();
00995     rc = curve->Read( file )?true:false;
00996     if ( curve->Count() == 1 ) {
00997       m_C2.Append( curve->HarvestSegment(0) );
00998       delete curve;
00999     }
01000     else
01001       m_C2.Append( curve );
01002   }
01003   const int c2_count = m_C2.Count();
01004 
01005   // 3d curves
01006   m_C3.Reserve(edge_count);
01007   for ( i = 0; rc && i < edge_count; i++ ) {
01008     ON_PolyCurve* curve = new ON_PolyCurve();
01009     rc = curve->Read( file )?true:false;
01010     if ( curve->Count() == 1 ) {
01011       m_C3.Append( curve->HarvestSegment(0) );
01012       delete curve;
01013     }
01014     else
01015       m_C3.Append( curve );
01016   }
01017   const int c3_count = m_C3.Count();
01018 
01019   // make a new edge for each 3d curve
01020   m_E.Reserve(c3_count);
01021   for ( i = 0; i < c3_count && rc; i++ ) 
01022   {
01023     NewEdge(i);
01024   }
01025 
01026   // 3d surfaces
01027   m_S.Reserve(face_count);
01028   for ( i = 0; rc && i < face_count; i++ ) {
01029     ON_NurbsSurface* surface = new ON_NurbsSurface();
01030     rc = surface->Read( file )?true:false;
01031     m_S.Append( surface );
01032   }
01033 
01034   ON_SimpleArray<int> te_index(trim_count);
01035   ON_SimpleArray<int> te_twin_index(trim_count);
01036 
01037   m_F.Reserve(face_count);
01038   m_L.Reserve(loop_count);
01039   m_T.Reserve(trim_count);
01040 
01041   for ( fi = 0; rc && fi < face_count; fi++ ) 
01042   {
01043     ftype_flag = 0;
01044     fbcnt = 0;
01045     ON_BrepFace& f = NewFace(fi);
01046     if (rc) rc = file.ReadInt( &i ); // legacy face index
01047     if (rc) rc = file.ReadInt( &i ); // OBSOLETE f.m_material_index
01048     int k = f.m_bRev;
01049     if (rc) rc = file.ReadInt( &k );
01050     if (rc) f.m_bRev = (k!=0);
01051     if (rc) rc = file.ReadInt( &ftype_flag );
01052     if (rc) rc = file.ReadPoint( f.m_bbox.m_min );
01053     if (rc) rc = file.ReadPoint( f.m_bbox.m_max );
01054     if (rc) rc = file.ReadInt( &fbcnt);
01055     if (fbcnt < 1 )
01056       rc = false;
01057     for ( fbi = 0; rc && fbi < fbcnt; fbi++ ) {
01058       btype_flag = 0;
01059       ON_BrepLoop::TYPE looptype = ON_BrepLoop::unknown;
01060       if (rc) rc = file.ReadInt( &i ); // legacy loop index
01061       if (rc) rc = file.ReadInt( &btype_flag );
01062       switch (btype_flag)
01063       {
01064       case 0:
01065         looptype = ON_BrepLoop::outer;
01066         break;
01067       case 1:
01068         looptype = ON_BrepLoop::inner;
01069         break;
01070       case -1:
01071         looptype = ON_BrepLoop::slit;
01072         break;
01073       default:
01074         looptype = ON_BrepLoop::unknown;
01075         break;
01076       }
01077       if (rc) rc = file.ReadDouble( 2, &bnd_2d_bbox.m_min.x );
01078       if (rc) rc = file.ReadDouble( 2, &bnd_2d_bbox.m_max.x );
01079       btcnt = 0;
01080       if (rc) rc = file.ReadInt( &btcnt );
01081       if (btcnt < 1 )
01082         rc = false;
01083       ON_BrepLoop& bnd = NewLoop(looptype,f);
01084       for ( bti = 0; rc && bti < btcnt; bti++ ) {
01085         ON_BrepTrim& trim = NewTrim(false,bnd,m_T.Count());
01086         te_index.Append(trim.m_trim_index);
01087         if (rc) rc = file.ReadInt( &i ); // legacy trim index
01088         if ( trim.m_trim_index != i )
01089         {
01090           ON_ERROR("ON_Brep::ReadOld200 - trim.m_trim_index out of synch.");
01091           //rc = false;
01092           //break;
01093         }
01094         if (rc) rc = file.ReadInt( &twin_index );
01095         te_twin_index.Append(twin_index);
01096         b = 0;
01097         if (rc) rc = file.ReadChar( &b ); // true if legacy trim managed 3d edge
01098         if (rc) rc = file.ReadInt( &trim.m_ei );
01099         if (b) {
01100           if ( trim.m_ei < 0 || trim.m_ei >= c3_count )
01101           {
01102             trim.m_ei = -1;
01103             ON_ERROR("ON_Brep::ReadOld201 - trim.m_ei out of range.");
01104             rc = false;
01105             break;
01106           }
01107         }
01108         if ( trim.m_trim_index >= 0 && trim.m_trim_index < c2_count )
01109           trim.m_c2i = trim.m_trim_index;
01110         else {
01111           ON_ERROR("ON_Brep::ReadOld200 - trim.m_trim_index out of range.");
01112           rc = false;
01113           trim.m_c2i = -1;
01114           break;
01115         }
01116         int k = trim.m_bRev3d;
01117         if (rc) rc = file.ReadInt(&k);
01118         if (rc) trim.m_bRev3d = (k!=0);
01119         if (rc) rc = file.ReadInt(&gcon_flag);
01120         if (rc) rc = file.ReadInt(&mono_flag);
01121         if (rc) rc = file.ReadDouble(&trim.m__legacy_3d_tol);
01122         if (rc) rc = file.ReadDouble(&trim.m__legacy_2d_tol);
01123       }
01124     }
01125   }
01126 
01127   // finish hooking trims to edges
01128   if (rc) {
01129     int trim_index;
01130     for ( i = 0; i < trim_count; i++ ) {
01131       trim_index = te_index[i];
01132       if ( trim_index >= 0 && trim_index < m_T.Count() )
01133         continue;
01134       twin_index = te_twin_index[i];
01135       if ( twin_index >= 0 && twin_index < m_T.Count() )
01136         continue;
01137       ON_BrepTrim& trim1 = m_T[trim_index];
01138       ON_BrepTrim& trim2 = m_T[twin_index];
01139       if ( trim1.m_ei >= 0 && trim1.m_ei < c2_count && trim2.m_ei < 0 )
01140         trim2.m_ei = trim1.m_ei;
01141       else if ( trim2.m_ei >= 0 && trim2.m_ei < c2_count && trim1.m_ei < 0 )
01142         trim1.m_ei = trim2.m_ei;
01143     }
01144     for ( i = 0; i < m_T.Count(); i++ ) {
01145       ON_BrepTrim& trim = m_T[i];
01146       ON_Curve* tcurve = m_C2[trim.m_c2i];
01147       trim.SetProxyCurve( tcurve );
01148       if ( trim.m_ei >= 0 && trim.m_ei < c3_count )
01149         m_E[trim.m_ei].m_ti.Append(trim.m_trim_index);
01150     }
01151 
01152 
01153     // finish setting flags
01154     SetTrimIsoFlags();
01155     SetTrimTypeFlags();
01156 
01157     // create 3d vertex information
01158     SetVertices();
01159 
01160     // set tols from values in file
01161     SetTolsFromLegacyValues();
01162 
01163   }
01164   else {
01165     Destroy();
01166   }
01167 
01168   if (rc) {
01169     // 3d render mesh geometry
01170     ON_Object* obj;
01171     for ( i = 0; rc && i < face_count; i++ ) {
01172       ON_BrepFace& f = m_F[i];
01173       file.ReadChar(&b);
01174       if (b) {
01175         obj = 0;
01176         rc = (file.ReadObject(&obj)==1)?true:false;
01177         f.m_render_mesh = ON_Mesh::Cast(obj);
01178         if ( !f.m_render_mesh )
01179           delete obj;
01180       }
01181     }
01182     if ( !rc ) {
01183       // delete render mesh geometry
01184       for ( i = 0; i < face_count; i++ ) {
01185         ON_BrepFace& f = m_F[i];
01186         if ( f.m_render_mesh ) {
01187           delete f.m_render_mesh;
01188           f.m_render_mesh = 0;
01189         }
01190       }
01191     }
01192 
01193     if (rc && minor_version >= 1) {
01194       // 3d analysis mesh geometry
01195       for ( i = 0; rc && i < face_count; i++ ) {
01196         ON_BrepFace& f = m_F[i];
01197         file.ReadChar(&b);
01198         if (b) {
01199           obj = 0;
01200           rc = file.ReadObject(&obj)?true:false;
01201           f.m_analysis_mesh = ON_Mesh::Cast(obj);
01202           if ( !f.m_analysis_mesh )
01203             delete obj;
01204         }
01205       }
01206       if ( !rc ) {
01207         // delete analysis mesh geometry
01208         for ( i = 0; i < face_count; i++ ) {
01209           ON_BrepFace& f = m_F[i];
01210           if ( f.m_analysis_mesh ) {
01211             delete f.m_analysis_mesh;
01212             f.m_analysis_mesh = 0;
01213           }
01214         }
01215       }
01216     }
01217 
01218     // fill in missing information
01219     ReadFillInMissingBoxes(*this);
01220 
01221     if (!rc ) {
01222       ON_ERROR("ON_Brep::ReadOld201() - trouble reading render/analysis meshes");
01223       rc = true;
01224     }
01225   }
01226 
01227   // 22 April 2003:
01228   //   Use outer_flag to set m_is_solid for closed solids
01229   //   with outward pointing normals.
01230   if ( 1 == outer_flag && IsSolid() )
01231     m_is_solid = 1;
01232 
01233   return rc;
01234 }
01235 
01236 bool ON_Brep::ReadOld100( ON_BinaryArchive& file )
01237 {
01238   // b-rep was written by old Rhino I/O tookit
01239   int sz, i;
01240 
01241   // 2d curve geometry
01242   file.ReadInt( &sz );
01243   if ( sz < 1 ) {
01244     return false;
01245   }
01246   m_C2.Reserve(sz);
01247   for ( i = 0; i < sz; i++ ) {
01248     m_C2.Append( Read100_BrepCurve( file ) );
01249   }
01250 
01251   // 3d curve geomery
01252   file.ReadInt( &sz );
01253   if ( sz < 1 ) {
01254     return false;
01255   }
01256   m_C3.Reserve(sz);
01257   for ( i = 0; i < sz; i++ ) {
01258     m_C3.Append( Read100_BrepCurve( file ) );
01259   }
01260 
01261   // surface geometry
01262   file.ReadInt( &sz );
01263   if ( sz < 1 ) {
01264     return false;
01265   }
01266   m_S.Reserve(sz);
01267   for ( i = 0; i < sz; i++ ) {
01268     m_S.Append( Read100_BrepSurface( file ) );
01269   }
01270   /*
01271     CRhinoChunk* pChunk;
01272     CRhinoNurbsSurface* pSurface;
01273     const int typecode, length;
01274     for ( i = 0; i < sz; i++ ) {
01275       file.ReadInt( &typecode );
01276       if ( typecode == TCODE_RHINO_OBJECT_NURBS_SURFACE && length > 0 ) {
01277         pSurface = (CRhinoNurbsSurface*)pChunk;
01278       }
01279       m_S.Append( pSurface );
01280     }
01281   */
01282 
01283   // read topology
01284 
01285   // vertices
01286   file.ReadInt( &sz );
01287   m_V.Reserve(sz);
01288   for ( i = 0; i < sz; i++ ) {
01289     m_V.AppendNew();
01290     m_V[i].Read(file);
01291   }
01292 
01293   // edges
01294   file.ReadInt( &sz );
01295   m_E.Reserve(sz);
01296   for ( i = 0; i < sz; i++ ) {
01297     m_E.AppendNew();
01298     m_E[i].Read(file);
01299   }
01300 
01301   // trims
01302   file.ReadInt( &sz );
01303   m_T.Reserve(sz);
01304   for ( i = 0; i < sz; i++ ) {
01305     m_T.AppendNew();
01306     m_T[i].Read(file);
01307   }
01308 
01309   // loops
01310   file.ReadInt( &sz );
01311   m_L.Reserve(sz);
01312   for ( i = 0; i < sz; i++ ) {
01313     m_L.AppendNew();
01314     m_L[i].Read(file);
01315   }
01316 
01317   // faces
01318   file.ReadInt( &sz );
01319   m_F.Reserve(sz);
01320   for ( i = 0; i < sz; i++ ) {
01321     m_F.AppendNew();
01322     m_F[i].Read(file);
01323   }
01324 
01325   // bounding box
01326   file.ReadPoint( m_bbox.m_min );
01327   file.ReadPoint( m_bbox.m_max );
01328 
01329   // fill in missing information
01330   ReadFillInMissingBoxes(*this);
01331 
01332   return true;
01333 }
01334 
01335 bool ON_Brep::ReadOld101( ON_BinaryArchive& file )
01336 {
01337   ON_Object*  pO = NULL;
01338   ON_Curve*   pC = NULL;
01339   ON_Surface* pS = NULL;
01340   int i, count;
01341 
01342   // 2d curves
01343   file.ReadInt( &count );
01344   m_C2.Reserve(count);
01345   for ( i = 0; i < count; i++ ) 
01346   {
01347     pO = NULL;
01348     file.ReadObject( &pO );
01349     pC = ON_Curve::Cast(pO);
01350     if ( !pC )
01351       delete pO; // ERROR!
01352     m_C2.Append( pC );
01353     pC = NULL;
01354     pO = NULL;
01355   }
01356 
01357   // 3d curves
01358   file.ReadInt( &count );
01359   m_C3.Reserve(count);
01360   for ( i = 0; i < count; i++ ) 
01361   {
01362     pO = NULL;
01363     file.ReadObject( &pO );
01364     pC = ON_Curve::Cast(pO);
01365     if ( !pC )
01366       delete pO; // ERROR!
01367     m_C3.Append( pC );
01368     pC = NULL;
01369     pO = NULL;
01370   }
01371 
01372   // untrimmed surfaces
01373   file.ReadInt( &count );
01374   m_S.Reserve(count);
01375   for ( i = 0; i < count; i++ ) 
01376   {
01377     pO = NULL;
01378     file.ReadObject( &pO );
01379     pS = ON_Surface::Cast(pO);
01380     if ( !pS )
01381       delete pO; // ERROR!
01382     m_S.Append( pS );
01383     pS = NULL;
01384     pO = NULL;
01385   }
01386 
01387   // vertices
01388   file.ReadInt( &count );
01389   m_V.Reserve(count);
01390   m_V.SetCount(count);
01391   for ( i = 0; i < count; i++ ) 
01392   {
01393     m_V[i].Read(file);
01394   }
01395 
01396   // edges
01397   file.ReadInt( &count );
01398   m_E.Reserve(count);
01399   m_E.SetCount(count);
01400   for ( i = 0; i < count; i++ ) 
01401   {
01402     ON_BrepEdge& edge = m_E[i];
01403     edge.Read(file);
01404     edge.SetProxyCurve( edge.m_c3i >= 0 ? m_C3[edge.m_c3i] : 0 );
01405     edge.m_brep = this;
01406   }
01407 
01408   // trims
01409   file.ReadInt( &count );
01410   m_T.Reserve(count);
01411   m_T.SetCount(count);
01412   for ( i = 0; i < count; i++ ) 
01413   {
01414     m_T[i].Read(file);
01415     ON_BrepTrim& trim = m_T[i];
01416     trim.SetProxyCurve( trim.m_c2i >= 0 ? m_C2[trim.m_c2i] : 0 );
01417     trim.m_brep = this;
01418   }
01419 
01420   // loops
01421   file.ReadInt( &count );
01422   m_L.Reserve(count);
01423   m_L.SetCount(count);
01424   for ( i = 0; i < count; i++ ) 
01425   {
01426     m_L[i].Read(file);
01427     m_L[i].m_brep = this;
01428   }
01429 
01430   // faces
01431   file.ReadInt( &count );
01432   m_F.Reserve(count);
01433   m_F.SetCount(count);
01434   for ( i = 0; i < count; i++ ) 
01435   {
01436     ON_BrepFace& face = m_F[i];
01437     face.Read(file);
01438     face.SetProxySurface(face.m_si >= 0 ? m_S[face.m_si] : 0);
01439     face.m_brep = this;
01440   }
01441 
01442   // bounding box
01443   file.ReadPoint( m_bbox.m_min );
01444   file.ReadPoint( m_bbox.m_max );
01445 
01446   // fill in missing information
01447   ReadFillInMissingBoxes(*this);
01448 
01449   return true;
01450 }
01451 
01452 ON_Curve* ON_Brep::Read100_BrepCurve( ON_BinaryArchive& ) const
01453 {
01454   // TODO - look at old Rhino I/O tookit code and read b-rep curves
01455   return NULL;
01456 }
01457 
01458 ON_Surface* ON_Brep::Read100_BrepSurface( ON_BinaryArchive& ) const
01459 {
01460   // TODO - look at old Rhino I/O tookit code and read b-rep surfaces
01461   return NULL;
01462 }
01463 


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:27:00