opennurbs_polyedgecurve.cpp
Go to the documentation of this file.
00001 #include "pcl/surface/3rdparty/opennurbs/opennurbs.h"
00002 #include "pcl/surface/3rdparty/opennurbs/opennurbs_polyedgecurve.h"
00003 
00004 ON_OBJECT_IMPLEMENT(ON_PolyEdgeSegment,ON_CurveProxy,"42F47A87-5B1B-4e31-AB87-4639D78325D6");
00005 
00006 ON_PolyEdgeSegment::ON_PolyEdgeSegment()
00007 {
00008   Init();
00009 }
00010 
00011 ON_PolyEdgeSegment::~ON_PolyEdgeSegment()
00012 {
00013   Init();
00014 }
00015 
00016 void ON_PolyEdgeSegment::Init()
00017 {
00018   m_component_index.UnSet();
00019   m_object_id = ON_nil_uuid;
00020   m_brep = 0;
00021   m_trim = 0;
00022   m_edge = 0;
00023   m_face = 0;
00024   m_surface = 0;
00025   m_edge_domain.Destroy();
00026   m_trim_domain.Destroy();
00027   ON_CurveProxy::SetProxyCurve(0);
00028 
00029   ClearEvalCacheHelper();
00030 }
00031 
00032 bool ON_PolyEdgeSegment::Create( 
00033                 const ON_BrepTrim* trim,
00034                 const ON_UUID& object_id
00035                 )
00036 {
00037   Init();
00038   if ( !trim )
00039     return false;
00040   if ( trim->m_ei >= 0 )
00041     return false;
00042   const ON_Brep* brep = trim->Brep();
00043   if ( !brep )
00044     return false;
00045   const ON_BrepEdge* edge = trim->Edge();
00046   if ( !edge )
00047     return false;
00048   const ON_Curve* c3 = edge->EdgeCurveOf();
00049   if ( !c3 )
00050     return false;
00051   m_brep = brep;
00052   m_trim = trim;
00053   m_edge = edge;
00054   m_face = trim->Face();
00055   if ( m_face )
00056     m_surface = m_face->SurfaceOf();
00057   m_edge_domain = m_edge->Domain();
00058   m_trim_domain = m_trim->Domain();
00059   ON_CurveProxy::SetProxyCurve( 
00060                     c3,
00061                     edge->ProxyCurveDomain()
00062                     );    
00063   if ( m_edge->ProxyCurveIsReversed() )
00064     ON_CurveProxy::Reverse();
00065   ON_CurveProxy::SetDomain( m_edge_domain[0], m_edge_domain[1] );
00066   m_component_index = trim->ComponentIndex();
00067   m_object_id = object_id;
00068   return true;
00069 }
00070 
00071 
00072 bool ON_PolyEdgeSegment::ReversedEdgeDir() const
00073 {
00074   bool rc = false;
00075   if ( m_edge )
00076   {
00077     rc = m_edge->ProxyCurveIsReversed() != ON_CurveProxy::ProxyCurveIsReversed();
00078   }
00079   return rc;
00080 }
00081 
00082 bool ON_PolyEdgeSegment::ReversedTrimDir() const
00083 {
00084   bool rc = false;
00085   if ( m_trim && m_edge )
00086   {
00087     rc = ReversedEdgeDir();
00088     if ( m_trim->m_bRev3d )
00089       rc = !rc;
00090   }
00091   return rc;
00092 }
00093 
00094 bool ON_PolyEdgeSegment::Create( 
00095           const ON_Curve* curve,
00096           const ON_UUID& object_id 
00097           )
00098 {
00099   //bool rc = false;
00100   Init();
00101   if ( !curve )
00102     return false;
00103   const ON_BrepEdge* edge = ON_BrepEdge::Cast(curve);
00104   if ( edge )
00105   {
00106     const ON_Brep* brep = edge->Brep();
00107     if ( !brep )
00108       return false;
00109     const ON_Curve* c3 = edge->EdgeCurveOf();
00110     if ( !c3 )
00111       return false;
00112     m_edge = edge;
00113     m_brep = brep;
00114     m_component_index = edge->ComponentIndex();
00115     m_edge_domain = m_edge->Domain();
00116     m_trim_domain = m_trim->Domain();
00117     ON_CurveProxy::SetProxyCurve( 
00118                       c3,
00119                       edge->ProxyCurveDomain()
00120                       );    
00121     if ( m_edge->ProxyCurveIsReversed() )
00122       ON_CurveProxy::Reverse();
00123     ON_CurveProxy::SetDomain( m_edge_domain[0], m_edge_domain[1] );
00124   }
00125   else
00126   {
00127     ON_CurveProxy::SetProxyCurve(const_cast<ON_Curve*>(curve));   
00128   }
00129   m_object_id = object_id;
00130   return true;
00131 }
00132 
00133 const ON_BrepEdge* ON_PolyEdgeSegment::Edge() const
00134 {
00135   return m_edge;
00136 }
00137 
00138 const ON_BrepTrim* ON_PolyEdgeSegment::Trim() const
00139 {
00140   return m_trim;
00141 }
00142 
00143 const ON_Brep* ON_PolyEdgeSegment::Brep() const
00144 {
00145   return m_brep;
00146 }
00147 
00148 const ON_BrepFace* ON_PolyEdgeSegment::Face() const
00149 {
00150   return m_face;
00151 }
00152 
00153 const ON_Surface*  ON_PolyEdgeSegment::Surface() const
00154 {
00155   return m_surface;
00156 }
00157 
00158 ON_Surface::ISO ON_PolyEdgeSegment::IsoType() const
00159 {
00160   return m_trim ? m_trim->m_iso : ON_Surface::not_iso;
00161 }
00162 
00163 ON_Interval ON_PolyEdgeSegment::EdgeDomain() const
00164 {
00165   return m_edge_domain;
00166 }
00167 
00168 ON_Interval ON_PolyEdgeSegment::TrimDomain() const
00169 {
00170   return m_trim_domain;
00171 }
00172 
00173 void ON_PolyEdgeSegment::ClearEvalCacheHelper()
00174 {
00175   m_t = ON_UNSET_VALUE;
00176   m_edge_t = ON_UNSET_VALUE;
00177   m_trim_t = ON_UNSET_VALUE;
00178   m_srf_uv[0] = ON_UNSET_VALUE;
00179   m_srf_uv[1] = ON_UNSET_VALUE;
00180   m_trim_hint = 0;
00181   m_edge_hint = 0;
00182   m_evsrf_hint[0] = 0;
00183   m_evsrf_hint[1] = 0;
00184   m_evsrf_uv[0] = ON_UNSET_VALUE;
00185   m_evsrf_uv[1] = ON_UNSET_VALUE;
00186   m_evsrf_pt = ON_UNSET_POINT;
00187 }
00188 
00189 double ON_PolyEdgeSegment::EdgeParameter(double t) const
00190 {
00191   double edge_t = ON_UNSET_VALUE;
00192   if ( m_edge )
00193   {
00194     if ( m_t == t && m_edge_t != ON_UNSET_VALUE )
00195       edge_t = m_edge_t;
00196     else
00197     {
00198       ON_PolyEdgeSegment* p = const_cast<ON_PolyEdgeSegment*>(this);
00199       if ( t != m_t )
00200       {
00201         p->m_t = t;
00202         p->m_trim_t = ON_UNSET_VALUE;
00203         p->m_srf_uv[0] = ON_UNSET_VALUE;
00204         p->m_srf_uv[1] = ON_UNSET_VALUE;
00205       }
00206       ON_Interval d = Domain();
00207       bool bReversedEdgeDir = ReversedEdgeDir();
00208       if ( bReversedEdgeDir || m_edge_domain != d )
00209       {
00210         double s = d.NormalizedParameterAt(t);
00211         if ( bReversedEdgeDir )
00212           s = 1.0 - s;
00213         edge_t = m_edge_domain.ParameterAt(s);
00214       }
00215       else
00216         edge_t = t;
00217       p->m_edge_t = edge_t;
00218     }
00219   }
00220   return edge_t;
00221 }
00222 
00223 
00224 ON_OBJECT_IMPLEMENT(ON_PolyEdgeCurve,ON_PolyCurve,"39FF3DD3-FE0F-4807-9D59-185F0D73C0E4");
00225 
00226 ON_PolyEdgeCurve::ON_PolyEdgeCurve()
00227 {
00228 }
00229 
00230 ON_PolyEdgeCurve::~ON_PolyEdgeCurve()
00231 {
00232 }
00233 
00234 ON_BOOL32 ON_PolyEdgeCurve::SetStartPoint( ON_3dPoint start_point )
00235 {
00236   return false; // cannot change edges
00237 }
00238 
00239 ON_BOOL32 ON_PolyEdgeCurve::SetEndPoint( ON_3dPoint end_point )
00240 {
00241   return false; // cannot change edges
00242 }
00243 
00244 ON_BOOL32 ON_PolyEdgeCurve::ChangeClosedCurveSeam( double t )
00245 {
00246   //int saved_is_closed_helper = m_is_closed_helper;
00247 
00248   if ( SegmentCount() == 1 )
00249   {
00250     // A ON_PolyEdgeSegment cannot have its start/end
00251     // changed. Split it into two segments and let 
00252     // ON_PolyCurve::ChangeClosedCurveSeam() do the work.
00253     if ( !IsClosed() )
00254       return false;
00255 
00256     ON_Interval crvd = Domain();
00257     double s = crvd.NormalizedParameterAt(t);
00258 
00259     if ( s <= ON_SQRT_EPSILON || s >= (1.0 - ON_SQRT_EPSILON) )
00260     {
00261       s = fmod(s,1.0);
00262       if ( s < 0.0 )
00263         s += 1.0;
00264       if ( fabs(s) <= ON_SQRT_EPSILON || fabs(1.0-s) <= ON_SQRT_EPSILON )
00265       {
00266         // split parameter is at start/end of this segemnt
00267         if ( t != crvd[0] )
00268         {
00269           DestroyRuntimeCache();
00270           SetDomain(t,t+crvd.Length() );
00271           //m_is_closed_helper = saved_is_closed_helper;
00272         }
00273         return true;
00274       }
00275       return false;
00276     }
00277 
00278     ON_PolyEdgeSegment* left_seg = SegmentCurve(0);
00279     if ( 0 == left_seg )
00280       return false;
00281 
00282     DestroyRuntimeCache();
00283 
00284     ON_Curve* left = left_seg;
00285     ON_Curve* right = 0;
00286     double segt = SegmentCurveParameter(t);
00287     if ( !left_seg->Split(segt,left,right) )
00288       return false;
00289     SetDomain(crvd[0],t);
00290     
00291     ON_PolyEdgeSegment* right_seg = ON_PolyEdgeSegment::Cast(right);
00292     if ( 0 == right_seg )
00293       return false;
00294     Append(right_seg);
00295 
00296     double st[3];
00297     st[0] = crvd[0];
00298     st[1] = t;
00299     st[2] = crvd[1];
00300     SetParameterization( st );
00301   }
00302 
00303   // ON_PolyCurve::ChangeClosedCurveSeam works fine on
00304   // two or more segments.
00305   ON_BOOL32 rc = ON_PolyCurve::ChangeClosedCurveSeam(t);
00306   //if ( saved_is_closed_helper )
00307   //  m_is_closed_helper = saved_is_closed_helper;
00308 
00309   return rc;
00310 }
00311 
00312 ON_BOOL32 ON_PolyEdgeCurve::PrependAndMatch(ON_Curve*)
00313 {
00314   return false; // cannot change edges
00315 }
00316 
00317 
00318 ON_BOOL32 ON_PolyEdgeCurve::AppendAndMatch(ON_Curve*)
00319 {
00320   return false; // cannot change edges
00321 }
00322 
00323 ON_Curve* ON_PolyEdgeSegment::DuplicateCurve() const
00324 {
00325   return ON_CurveProxy::DuplicateCurve();
00326 
00327   // 21 December 2004 Dale Lear
00328   //     This is wrong.  I did it some time ago as a quick
00329   //     fix for one of Lowell's early uses of CRhinoPolyEdges
00330   //     however, this will cause lots of crashes now that
00331   //     all commands have to deal with polyedges and the code
00332   //     in those commands assumes that DuplicateCurve() returns
00333   //     a valid stand-alone curve.  If you end up here and
00334   //     wish this code still worked the old way, please get
00335   //     in touch with Dale Lear and we'll find a way to get
00336   //     your code to work.
00337   // NO // ON_PolyEdgeSegment* dup = Duplicate();
00338   // NO // return dup;
00339 }
00340 
00341 ON_Curve* ON_PolyEdgeCurve::DuplicateCurve() const
00342 {
00343   return ON_PolyCurve::DuplicateCurve();
00344 
00345   // 21 December 2004 Dale Lear
00346   //     The code below is wrong.  I wrote it some time ago as a quick
00347   //     fix for one of Lowell's early uses of CRhinoPolyEdges
00348   //     however, this will cause lots of crashes now that
00349   //     all commands have to deal with polyedges and the code
00350   //     in those commands assumes that DuplicateCurve() returns
00351   //     a valid stand-alone curve.  If you end up here and
00352   //     wish this code still worked the old way, please get
00353   //     in touch with Dale Lear and we'll find a way to get
00354   //     your code to work.
00355 
00356         // NO //  int cnt = Count();
00357   // NO //  ON_SimpleArray<double> t(cnt+1);
00358         // NO //  ON_PolyEdgeCurve* dup_crv = new ON_PolyEdgeCurve();
00359   // NO //  
00360   // NO //  t.Append(Domain()[0]);
00361   // NO // 
00362   // NO // for( int i=0; i<cnt; i++)
00363   // NO //  {
00364   // NO //      const ON_Curve* seg = SegmentCurve(i);
00365   // NO //    if ( seg )
00366   // NO //    {
00367   // NO //      t.Append(SegmentDomain(i)[1]);
00368   // NO //      dup_crv->ON_PolyCurve::Append( seg->DuplicateCurve() );
00369   // NO //    }
00370   // NO // }    
00371   // NO // 
00372   // NO //  if( cnt > 0 && cnt+1 == t.Count() )
00373   // NO //  {
00374   // NO //    dup_crv->SetParameterization( t.Array() );
00375   // NO //  }
00376   // NO // 
00377   // NO //  dup_crv->m_ev_srf_tan_mode = m_ev_srf_tan_mode;
00378   // NO //  dup_crv->m_is_closed_helper = m_is_closed_helper;
00379   // NO // 
00380   // NO // return dup_crv;
00381 }
00382 
00383 ON_BOOL32 ON_PolyEdgeSegment::IsClosed(void) const
00384 {
00385   ON_BOOL32 rc = ON_CurveProxy::IsClosed();
00386   if ( !rc
00387        && m_edge
00388        && m_edge->m_vi[0] == m_edge->m_vi[1]
00389        && m_edge->ProxyCurve() == ProxyCurve()
00390        && m_edge->ProxyCurveDomain() == ProxyCurveDomain()
00391        && 0 != ProxyCurve()
00392        && ProxyCurve()->Domain() == ProxyCurveDomain()
00393        )
00394   {
00395     rc = m_edge->IsClosed();
00396   }
00397   return rc;
00398 }
00399 
00400 // 7-1-03 lw added override to unset cached closed flag
00401 // when a segment is removed
00402 ON_BOOL32 ON_PolyEdgeCurve::Remove( int segment_index )
00403 {
00404   ON_BOOL32 rc = ON_PolyCurve::Remove( segment_index);
00405   //if( rc)
00406   //  m_is_closed_helper = 0;  // Cached closed flag...
00407   return rc;
00408 }
00409 ON_BOOL32 ON_PolyEdgeCurve::Remove( )
00410 {
00411   return Remove(Count()-1);
00412 }
00413 
00414 ON_BOOL32 ON_PolyEdgeCurve::IsClosed(void) const
00415 {
00416   ON_BOOL32 rc = ON_PolyCurve::IsClosed();
00417 
00418   if ( !rc && SegmentCount() > 1 )
00419   {
00420     // Since the segments that make up a ON_PolyEdgeCurve
00421     // cannot have their ends matched (becuase the curves
00422     // belong to objects alread in the rhino model), 
00423     // the IsClosed() test has to tolerate larger gaps
00424     // in brep topology.
00425     //
00426     // If the start and end segments are edges that belong
00427     // to the same brep, then they "join" if and only if 
00428     // they share a vertex.
00429     const ON_PolyEdgeSegment* seg0 = SegmentCurve(0);
00430     const ON_PolyEdgeSegment* seg1 = SegmentCurve(SegmentCount()-1);
00431 
00432     const ON_BrepEdge* edge0 = seg0->Edge();
00433     const ON_BrepEdge* edge1 = seg1->Edge();
00434     
00435     if ( edge0 && edge1 && edge0->Brep() == edge1->Brep() )
00436     {
00437       // check for topological closure
00438       //
00439       // Do NOT add a test for sloppy geometric closure here.
00440       // If the edges are in the same brep and they don't 
00441       // meet topologicially, then there is something in the
00442       // brep that is separating the edges.
00443       int evi0 = seg0->ReversedEdgeDir() ? 1 : 0;
00444       int evi1 = seg1->ReversedEdgeDir() ? 0 : 1;
00445       double et0 = seg0->EdgeParameter(seg0->Domain()[0]);
00446       double et1 = seg1->EdgeParameter(seg1->Domain()[1]);
00447       if ( et0 != ON_UNSET_VALUE && et1 != ON_UNSET_VALUE )
00448       {
00449         ON_Interval edom0 = edge0->Domain();
00450         ON_Interval edom1 = edge1->Domain();
00451         if ( et0 == edom0[evi0] && et1 == edom1[evi1] )
00452         {
00453           // The polyedge starts at the (evi0?end:start) of edge0
00454           // and ends at the (ev1?end:start) of edge1.
00455           if ( edge0->m_vi[evi0] == edge1->m_vi[evi1] )
00456           {
00457             // the polyedge start/ends at a common vertex
00458             rc = true;
00459           }
00460         }
00461         else if ( edge0 == edge1 
00462                   && fabs(et0-et1) <= ON_ZERO_TOLERANCE 
00463                   && edom0.Includes(et0,true)
00464                   && edom1.Includes(et1,true)
00465                   )
00466         {
00467           // The start/end of the polyedge is an interior point
00468           // of a single edge.  (This happens when the "seam" gets
00469           // adjusted to be inside of an edge.)  It is unlikely that
00470           // ON_PolyCurve::IsClosed() would return false in this
00471           // case, but this check should keep everybody happy.
00472           rc = true;
00473         }
00474       }
00475     }
00476   }
00477 
00478   return rc;
00479 }
00480 
00481 bool ON_PolyEdgeCurve::Create( const ON_BrepTrim* trim, const ON_UUID& object_id )
00482 {
00483   bool rc = false;
00484   Destroy();
00485   //m_is_closed_helper = 0;
00486   if ( trim )
00487   {
00488     ON_PolyEdgeSegment* segment = new ON_PolyEdgeSegment();
00489     rc = segment->Create(trim,object_id);
00490     if (rc )
00491       Append(segment);
00492     else
00493       delete segment;
00494   }
00495   return rc;
00496 }
00497 
00498 bool ON_PolyEdgeCurve::Create( const ON_Curve* curve, const ON_UUID& object_id )
00499 {
00500   bool rc = false;
00501   Destroy();
00502   //m_is_closed_helper = 0;
00503   if ( curve )
00504   {
00505     ON_PolyEdgeSegment* segment = new ON_PolyEdgeSegment();
00506     rc = segment->Create(curve,object_id);
00507     if (rc )
00508       Append(segment);
00509     else
00510       delete segment;
00511   }
00512   return rc;
00513 }
00514 
00515 int ON_PolyEdgeCurve::SegmentCount() const
00516 {
00517   return ON_PolyCurve::Count();
00518 }
00519 
00520 ON_PolyEdgeSegment* ON_PolyEdgeCurve::SegmentCurve(
00521   int segment_index
00522   ) const
00523 {
00524   return ON_PolyEdgeSegment::Cast(ON_PolyCurve::SegmentCurve(segment_index));
00525 }
00526 
00527 
00528 ON_PolyEdgeSegment* ON_PolyEdgeCurve::operator[](int segment_index) const
00529 {
00530   return SegmentCurve(segment_index);
00531 }
00532 
00533 void ON_PolyEdgeCurve::DestroyRuntimeCache( bool bDelete )
00534 {
00535   //m_is_closed_helper = 0;
00536   ON_PolyCurve::DestroyRuntimeCache(bDelete);
00537 }
00538 
00539 void ON_PolyEdgeSegment::DestroyRuntimeCache( bool bDelete )
00540 {
00541   ClearEvalCacheHelper();
00542   ON_CurveProxy::DestroyRuntimeCache(bDelete);
00543 }
00544 
00545 
00546 ON_BOOL32 ON_PolyEdgeCurve::Prepend( ON_PolyEdgeSegment* new_segment )
00547 {
00548   DestroyRuntimeCache();
00549   ON_BOOL32 rc = false;
00550   if ( new_segment )
00551   {
00552     if ( Count() > 0 )
00553     {
00554       // keep segment domains in synch with polycurve domain
00555       // so that parameter bookkeeping is easy.
00556       ON_Interval cdom = Domain();
00557       ON_Interval sdom = new_segment->Domain();
00558       if ( sdom[1] != cdom[0] )
00559       {
00560         sdom[0] = cdom[0] - sdom.Length();
00561         sdom[1] = cdom[0];
00562         new_segment->SetDomain(sdom[0],sdom[1]);
00563       }
00564     }
00565     rc = ON_PolyCurve::Prepend(new_segment);
00566   }
00567   return rc;
00568 }
00569 
00570 ON_BOOL32 ON_PolyEdgeCurve::Append( ON_PolyEdgeSegment* new_segment )
00571 {
00572   DestroyRuntimeCache();
00573   ON_BOOL32 rc = false;
00574   if ( new_segment )
00575   {
00576     //m_is_closed_helper = 0;
00577     if ( Count() > 0 )
00578     {
00579       // keep segment domains in synch with polycurve domain
00580       // so that parameter bookkeeping is easy.
00581       ON_Interval cdom = Domain();
00582       ON_Interval sdom = new_segment->Domain();
00583       if ( sdom[0] != cdom[1] )
00584       {
00585         sdom[1] = cdom[1] + sdom.Length();
00586         sdom[0] = cdom[1];
00587         new_segment->SetDomain(sdom[0],sdom[1]);
00588       }
00589     }
00590     rc = ON_PolyCurve::Append(new_segment);
00591   }
00592   return rc;
00593 }
00594 
00595 ON_BOOL32 ON_PolyEdgeCurve::Insert( 
00596          int segment_index,
00597          ON_PolyEdgeSegment* new_segment
00598          )
00599 {
00600   DestroyRuntimeCache();
00601   ON_BOOL32 rc = false;
00602   if ( segment_index > 0 )
00603   {
00604     //m_is_closed_helper = 0;
00605     rc = ON_PolyCurve::Insert(segment_index,new_segment);
00606     if ( rc )
00607     {
00608       int i;
00609       for ( i = segment_index; i < Count(); i++ )
00610       {
00611         ON_PolyEdgeSegment* seg = SegmentCurve(i);
00612         ON_Interval d = SegmentDomain(i);
00613         seg->SetDomain(d[0],d[1]);
00614       }
00615     }
00616   }
00617   else if ( segment_index == 0 )
00618     rc = Prepend(new_segment);
00619   return rc;
00620 }
00621 
00622 const ON_BrepEdge* ON_PolyEdgeCurve::EdgeAt(double t) const
00623 {
00624   ON_PolyEdgeSegment* seg = SegmentCurve( SegmentIndex(t) );
00625   return seg ? seg->Edge() : 0;
00626 }
00627 
00628 const ON_BrepTrim* ON_PolyEdgeCurve::TrimAt(double t) const
00629 {
00630   ON_PolyEdgeSegment* seg = SegmentCurve( SegmentIndex(t) );
00631   return seg ? seg->Trim() : 0;
00632 }
00633 
00634 const ON_Brep*     ON_PolyEdgeCurve::BrepAt(double t) const
00635 {
00636   ON_PolyEdgeSegment* seg = SegmentCurve( SegmentIndex(t) );
00637   return seg ? seg->Brep() : 0;
00638 }
00639 
00640 const ON_BrepFace* ON_PolyEdgeCurve::FaceAt(double t) const
00641 {
00642   ON_PolyEdgeSegment* seg = SegmentCurve( SegmentIndex(t) );
00643   return seg ? seg->Face() : 0;
00644 }
00645 
00646 const ON_Surface*  ON_PolyEdgeCurve::SurfaceAt(double t) const
00647 {
00648   ON_PolyEdgeSegment* seg = SegmentCurve( SegmentIndex(t) );
00649   return seg ? seg->Surface() : 0;
00650 }
00651 
00652 ON_Surface::ISO ON_PolyEdgeCurve::IsoType( double t) const
00653 {
00654   ON_PolyEdgeSegment* seg = SegmentCurve( SegmentIndex(t) );
00655   return seg ? seg->IsoType() : ON_Surface::not_iso;
00656 }
00657 
00658 
00659 double ON_PolyEdgeCurve::EdgeParameter(double t) const
00660 {
00661   double edge_t = ON_UNSET_VALUE;
00662   int segment_index = SegmentIndex(t);
00663   ON_PolyEdgeSegment* seg = SegmentCurve( segment_index );
00664   if ( seg )
00665   {
00666     ON_Interval pdom = SegmentDomain(segment_index);
00667     ON_Interval sdom = seg->Domain();
00668     if ( sdom != pdom )
00669     {
00670       double s = pdom.NormalizedParameterAt(t);
00671       t = sdom.ParameterAt(s);
00672     }
00673     edge_t = seg->EdgeParameter(t);
00674   }
00675   return edge_t;
00676 }
00677 
00678 // Test if there are any surface edges in the polyedge
00679 bool ON_PolyEdgeCurve::ContainsAnyEdges() const
00680 {
00681   int i, count = SegmentCount();
00682   for( i = 0; i < count; i++)
00683   {
00684     ON_PolyEdgeSegment* segment = SegmentCurve(i);
00685     if( 0 != segment && NULL != segment->Edge())
00686     {
00687       return true;
00688     }
00689   }
00690   return false;
00691 }
00692 
00693 // Test if all segments of the polyedge are surface edges
00694 bool ON_PolyEdgeCurve::ContainsAllEdges() const
00695 {
00696   int i, count = SegmentCount();
00697   for( i = 0; i < count; i++)
00698   {
00699     ON_PolyEdgeSegment* segment = SegmentCurve(i);
00700     if( NULL == segment || NULL == segment->Edge())
00701     {
00702       return false;
00703     }
00704   }
00705   return true;
00706 }
00707 
00708 int ON_PolyEdgeCurve::FindEdge( const ON_BrepEdge* edge) const
00709 {
00710   int rc = -1;
00711   if ( 0 != edge )
00712   {
00713     int i, count = SegmentCount();
00714     for( i = 0; i < count; i++)
00715     {
00716       ON_PolyEdgeSegment* segment = SegmentCurve(i);
00717       if ( 0 != segment && edge == segment->Edge() )
00718       {
00719         rc = i;
00720         break;
00721       }
00722     }
00723   }
00724   return rc;
00725 }
00726 
00727 int ON_PolyEdgeCurve::FindTrim( const ON_BrepTrim* trim) const
00728 {
00729   int rc = -1;
00730   if ( 0 != trim )
00731   {
00732     int i, count = SegmentCount();
00733     for( i = 0; i < count; i++)
00734     {
00735       ON_PolyEdgeSegment* segment = SegmentCurve(i);
00736       if ( 0 != segment && trim == segment->Trim() )
00737       {
00738         rc = i;
00739         break;
00740       }
00741     }
00742   }
00743   return rc;
00744 }
00745 
00746 int ON_PolyEdgeCurve::FindCurve( const ON_Curve* curve) const
00747 {
00748   int rc = -1;
00749   if ( 0 != curve )
00750   {
00751     int i, count = SegmentCount();
00752     for( i = 0; i < count; i++)
00753     {
00754       ON_PolyEdgeSegment* segment = SegmentCurve(i);
00755       if (    0 != segment 
00756            && (curve == segment || curve == segment->ProxyCurve() || curve == segment->Edge()) )
00757       {
00758         rc = i;
00759         break;
00760       }
00761     }
00762   }
00763   return rc;
00764 }
00765 
00766 ON_BOOL32 ON_PolyEdgeSegment::Write( ON_BinaryArchive& archive ) const
00767 {
00768   bool rc = archive.BeginWrite3dmChunk(TCODE_ANONYMOUS_CHUNK,1,0);
00769   if (!rc)
00770     return false;
00771   for(;;)
00772   {
00773     rc = archive.WriteUuid(m_object_id);
00774     if (!rc) break;
00775     rc = archive.WriteComponentIndex(m_component_index);
00776     if (!rc) break;
00777     rc = archive.WriteInterval(m_edge_domain);
00778     if (!rc) break;
00779     rc = archive.WriteInterval(m_trim_domain);
00780     if (!rc) break;
00781     bool b = ON_CurveProxy::ProxyCurveIsReversed();
00782     rc = archive.WriteBool(b);
00783     if (!rc) break;
00784     rc = archive.WriteInterval(ON_CurveProxy::Domain());
00785     if (!rc) break;
00786     rc = archive.WriteInterval(ON_CurveProxy::ProxyCurveDomain());
00787     if (!rc) break;
00788 
00789     break;
00790   }
00791   if ( !archive.EndWrite3dmChunk() )
00792     rc = false;
00793   return rc;
00794 }
00795 
00796 ON_BOOL32 ON_PolyEdgeSegment::Read( ON_BinaryArchive& archive )
00797 {
00798   Init();
00799   int major_version = 0;
00800   int minor_version = 0;
00801   bool rc = archive.BeginRead3dmChunk(TCODE_ANONYMOUS_CHUNK,&major_version,&minor_version);
00802   if (!rc)
00803     return false;
00804   for(;;)
00805   {
00806     rc = (1 == major_version);
00807     if ( !rc )
00808       break;
00809 
00810     rc = archive.ReadUuid(m_object_id);
00811     if (!rc) break;
00812     rc = archive.ReadComponentIndex(m_component_index);
00813     if (!rc) break;
00814     rc = archive.ReadInterval(m_edge_domain);
00815     if (!rc) break;
00816     rc = archive.ReadInterval(m_trim_domain);
00817     if (!rc) break;
00818 
00819     // Read ON_ProxyCurve values we need
00820     bool bReversed = false;
00821     rc = archive.ReadBool(&bReversed);
00822     if (!rc) break;
00823     ON_Interval this_domain;
00824     rc = archive.ReadInterval(this_domain);
00825     if (!rc) break;
00826     ON_Interval real_curve_domain;
00827     rc = archive.ReadInterval(real_curve_domain);
00828     if (!rc) break;
00829 
00830     if ( bReversed)
00831       ON_CurveProxy::Reverse();
00832     ON_CurveProxy::SetDomain(this_domain);
00833     ON_CurveProxy::SetProxyCurveDomain(real_curve_domain);
00834 
00835     break;
00836   }
00837   if ( !archive.EndRead3dmChunk() )
00838     rc = false;
00839   return rc;
00840 }
00841 


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