Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGDVRClipGeometry.cpp

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000,2001 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011  \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028  \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037  \*---------------------------------------------------------------------------*/
00038 
00039 //---------------------------------------------------------------------------
00040 //  Includes
00041 //---------------------------------------------------------------------------
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 
00046 #include <OSGConfig.h>
00047 #include <OSGTriangleIterator.h>
00048 #include <OSGVector.h>
00049 #include <OSGGeometry.h>
00050 
00051 
00052 #include <OSGDVRVertex.h>
00053 #include <OSGDVRTriangle.h>
00054 #include <OSGDVRClipGeometry.h>
00055 
00056 OSG_USING_NAMESPACE
00057 
00062 /*----------------------- constructors & destructors ----------------------*/
00063 
00064 // Constructor
00065 DVRClipGeometry::DVRClipGeometry(void) :
00066     Inherited()
00067 {
00068     initialized             = false;
00069     maxActiveTrianglesCount = 4;
00070     activeTrianglesCount    = 0;
00071     maxSeedVerticesCount    = 4;
00072     seedVerticesCount       = 0;
00073 
00074     activeTriangles         =  
00075         (DVRTriangle **) malloc(maxActiveTrianglesCount * 
00076                                 sizeof(DVRTriangle *)   );
00077 
00078     seedVertices = 
00079         (DVRVertex   **) malloc(maxSeedVerticesCount    *
00080                                 sizeof(DVRVertex *)     );
00081 }
00082 
00083 // Copy Constructor
00084 DVRClipGeometry::DVRClipGeometry(const DVRClipGeometry &source) :
00085     Inherited(source)
00086 {
00087     initialized             = false;
00088     maxActiveTrianglesCount = 4;
00089     activeTrianglesCount    = 0;
00090     maxSeedVerticesCount    = 4;
00091     seedVerticesCount       = 0;
00092 
00093     activeTriangles =  
00094         (DVRTriangle **) malloc(maxActiveTrianglesCount * 
00095                                 sizeof(DVRTriangle *)   );
00096 
00097     seedVertices = 
00098         (DVRVertex   **) malloc(maxSeedVerticesCount    * 
00099                                 sizeof(DVRVertex   *)   );
00100 }
00101 
00102 // Destructor
00103 DVRClipGeometry::~DVRClipGeometry(void)
00104 {
00105     if(activeTriangles)
00106         free(activeTriangles); // allocation with malloc/realloc!!
00107 
00108     if(seedVertices)
00109         free(seedVertices); // allocation with malloc/realloc!!
00110 }
00111 
00112 /*----------------------------- class specific ----------------------------*/
00113 
00114 // initialize the static features of the class, e.g. action callbacks
00115 void DVRClipGeometry::initMethod(void)
00116 {
00117 }
00118 
00119 // react to field changes
00120 void DVRClipGeometry::changed(BitVector whichField, UInt32 origin)
00121 {
00122     Inherited::changed(whichField, origin);
00123 
00124     if ((whichField & GeometryNodeFieldMask))
00125     {
00126         initialized = false;
00127     }
00128 }
00129 
00130 // output the instance for debug purposes
00131 void DVRClipGeometry::dump(      UInt32    , 
00132                           const BitVector ) const
00133 {
00134     //    _sfGeometry.dump();
00135     //    _sfBeacon.dump();
00136     SLOG << "Dump DVRClipGeometry NI" << std::endl;
00137 }
00138 
00139 // create the triangled geometry data structure
00140 Int32 DVRClipGeometry::insertVertex(Int32 idx)
00141 {
00142     for(UInt32 i = 0; i < _mfVertices.size(); i++)
00143     {
00144         if(_mfVertices[i].pos == geometry->getPositions()->getValue(idx))
00145             return i;
00146     }
00147 
00148     DVRVertex newVertex;
00149 
00150     newVertex.pos = geometry->getPositions()->getValue(idx);
00151 
00152     _mfVertices.push_back(newVertex);
00153 
00154     return _mfVertices.size() - 1;
00155 }
00156 
00157 
00158 bool DVRClipGeometry::buildTriangledGeometry(void)
00159 {
00160     // create triangles 
00161     for(TriangleIterator triangleIt  = geometry->beginTriangles(); 
00162                          triangleIt != geometry->endTriangles  ();
00163                        ++triangleIt)
00164     {
00165         DVRTriangle newTriangle;
00166         
00167         for(UInt32 i = 0; i < 3; i++)
00168         {
00169             Int32 vertexIndex = triangleIt.getPositionIndex(i);
00170             
00171             vertexIndex = insertVertex(vertexIndex);
00172 
00173             newTriangle.vertices[i] = vertexIndex;
00174             
00175             _mfVertices[vertexIndex].adjacentTriangles.push_back(
00176                 _mfTriangles.size());
00177 
00178             newTriangle.cutPnt  [i] = 0.0;
00179             newTriangle.cutPoint[i] = 0.0;
00180         }
00181         
00182         // compute normal and check orientation
00183         newTriangle.normal = 
00184             (_mfVertices[newTriangle.vertices[0]].pos -
00185              _mfVertices[newTriangle.vertices[1]].pos).cross(
00186                  _mfVertices[newTriangle.vertices[0]].pos -
00187                  _mfVertices[newTriangle.vertices[2]].pos);
00188 
00189         newTriangle.normal.normalize();
00190     
00191         if(newTriangle.normal.dot(triangleIt.getNormal(0)) < 0.0)
00192             newTriangle.normal.negate();      
00193     
00194         _mfTriangles.push_back(newTriangle);
00195     }
00196 
00197     // find neighbouring triangles
00198     for(UInt32 i = 0; i < _mfTriangles.size(); i++)
00199     {
00200         Int32 *vertices = _mfTriangles[i].vertices;   
00201 
00202         for(UInt32 l = 0; l < 3; l++)
00203         {
00204             const DVRVertex &v0 = _mfVertices[vertices[l]];
00205             const DVRVertex &v1 = _mfVertices[vertices[(l + 1) % 3]];
00206             
00207             for(UInt32 j = 0; j < v0.adjacentTriangles.size(); j++)
00208             {
00209                 for(UInt32 k = 0; k < v1.adjacentTriangles.size(); k++)
00210                 {
00211                     if(v0.adjacentTriangles[j] == v1.adjacentTriangles[k] &&
00212                        v0.adjacentTriangles[j] != i                       && 
00213                        v1.adjacentTriangles[k] != i                         )
00214                     {     
00215                         if(_mfTriangles[i].neighbours[l] != -1)
00216                         {
00217                             SLOG << "Error: Could not build clip geometry"
00218                                  << std::endl
00219                                  << "        one triangle edge shared by more "
00220                                  << "than two triangles" 
00221                                  << std::endl;
00222 
00223                             return false;
00224                         }
00225                         
00226                         _mfTriangles[i].neighbours[l] = 
00227                             v1.adjacentTriangles[k];
00228                     }
00229                 }
00230             }
00231         }
00232     }
00233     
00234     // check for non-closed geometry
00235     UInt32 checkCount = 0; 
00236 
00237     for(UInt32 i = 0; i < _mfTriangles.size(); i++)
00238     {
00239         for(UInt32 j = 0; j < 3; j++)
00240         {
00241             if(_mfTriangles[i].neighbours[j] == -1)
00242             {
00243                 checkCount++;
00244             }
00245         }
00246     }
00247 
00248     if(checkCount > 0)
00249     {
00250         SLOG << "Error: Could not build clip geometry" 
00251              << std::endl
00252              << checkCount
00253              << "open edges found!"
00254              << std::endl;
00255 
00256         return false;
00257     }
00258     
00259     return true;
00260 }
00261 
00262 bool DVRClipGeometry::isCut(DVRTriangle *tri, 
00263                             Real32       dist2RefPlane, 
00264                             DVRVertex   *switchedVertices[3])
00265 {
00266     bool v[3] = {false, false, false};
00267 
00268     bool vertexSwitched;
00269     int  countSwitchedVertices = 0;
00270 
00271     switchedVertices[0] = NULL;
00272     switchedVertices[1] = NULL;
00273     switchedVertices[2] = NULL;
00274 
00275     // for every vertex, check if it is in front of or behind the current 
00276     // reference plane and if it has moved behind the plane
00277 
00278     for(UInt32 i = 0; i < 3; i++)
00279     {
00280         v[i] = _mfVertices[tri->vertices[i]].isBehindPlane(dist2RefPlane, 
00281                                                            vertexSwitched);
00282         if(vertexSwitched)
00283         {
00284             vertexSwitched = false;
00285 
00286             switchedVertices[countSwitchedVertices] = 
00287                 &_mfVertices[tri->vertices[i]];
00288 
00289             countSwitchedVertices++;
00290         }
00291     }
00292 
00293     bool cut = false;
00294 
00295     // remember the cut edges for faster (and correct ;-) contour tracing...
00296     for(UInt32 i = 0; i < 3; i++)
00297     {
00298         if(v[i] ^ v[(i + 1) % 3])
00299         {
00300             tri->edgeCut[i] = true;
00301             cut             = true;
00302         }
00303         else
00304         {
00305             tri->edgeCut[i] = false;
00306         }
00307     }
00308   
00309     return cut;
00310 }
00311 
00312 
00313 // Prepare the object for clipping a volume's slices 
00314 void DVRClipGeometry::initialize(const Matrix &volumeToWorld)
00315 {
00316     if(!initialized)
00317     {
00318         _mfVertices.clear ();
00319         _mfTriangles.clear();
00320 
00321         if(getGeometryNode() != NullFC)
00322         {
00323             if(getGeometryNode()->getCore() != NullFC)
00324             {                
00325                 geometry = GeometryPtr::dcast(getGeometryNode()->getCore());
00326 
00327                 if(geometry != NullFC)
00328                     initialized = buildTriangledGeometry();
00329             }
00330         }
00331     }
00332 
00333     if(!initialized) 
00334         return;
00335 
00336     Matrix old    = toVolumeSpace;
00337 
00338     toVolumeSpace = volumeToWorld;
00339     toVolumeSpace.invert();
00340 
00341     NodePtr beacon =  getBeacon();
00342 
00343     if(beacon != NullFC)
00344     {
00345         toVolumeSpace.mult(beacon->getToWorld());
00346     }
00347     else if(getGeometryNode() != NullFC)
00348     {    
00349         toVolumeSpace.mult(getGeometryNode()->getToWorld());
00350     }
00351 
00352     Matrix toVolumeSpaceInvT;
00353 
00354     toVolumeSpace    .inverse(toVolumeSpaceInvT);
00355     toVolumeSpaceInvT.transpose();
00356 
00357     UInt32 numVertices = _mfVertices.size();
00358 
00359     // transform vertices to volume's space
00360     for(UInt32 i = 0; i < numVertices; i++)
00361     {
00362         toVolumeSpace.multMatrixPnt(_mfVertices[i].pos, 
00363                                     _mfVertices[i].transformedPos);
00364     }
00365 
00366     UInt32 numTriangles = _mfTriangles.size();
00367 
00368     // transform triangle normals to volume's space
00369     for(UInt32 i = 0; i < numTriangles; i++)
00370     {
00371         toVolumeSpaceInvT.multMatrixVec(_mfTriangles[i].normal, 
00372                                         _mfTriangles[i].transformedNormal);
00373 
00374         _mfTriangles[i].transformedNormal.normalize();
00375     }
00376 }
00377 
00378 // Prepare the object for clipping a volume's slices 
00379 void DVRClipGeometry::resetLocalData(void)
00380 {
00381     UInt32 numVertices = _mfVertices.size();
00382 
00383     for(UInt32 i = 0; i < numVertices; i++)
00384     {
00385         DVRVertex &vertex  = _mfVertices[i];
00386 
00387         vertex.behindPlane = false;
00388     }
00389 
00390     UInt32 numTriangles = _mfTriangles.size();
00391 
00392     // initialize the triangles local data
00393     for(UInt32 i = 0; i < numTriangles; i++)
00394     {
00395         _mfTriangles[i].visited   = false;
00396         _mfTriangles[i].inContour = false;
00397 
00398         for (UInt32 j = 0; j < 3; j++)
00399             _mfTriangles[i].edgeCut[j] = false;
00400     }
00401 }
00402 
00403 void DVRClipGeometry::setReferencePlane(const Plane &referencePlane)
00404 {
00405     UInt32 numVertices = _mfVertices.size();
00406     
00407     for(UInt32 i = 0; i < numVertices; i++)
00408         _mfVertices[i].calculatePlaneDistanceTransformed(referencePlane);
00409 }
00410 
00411 void DVRClipGeometry::computeSeedVertices(void)
00412 {
00413     if(!initialized) 
00414         return;
00415 
00416     // clear seed vertex list and active triangle list
00417     seedVerticesCount    = 0;
00418     activeTrianglesCount = 0;
00419 
00420     UInt32 numVertices = _mfVertices.size();
00421   
00422     // compute initial seed vertex set
00423     for(UInt32 i = 0; i < numVertices; i++)
00424     {
00425         if(isLocalMinimum(_mfVertices[i]))
00426         {
00427             if(maxSeedVerticesCount <= seedVerticesCount)
00428             {
00429                 maxSeedVerticesCount *= 2;
00430 
00431                 seedVertices = 
00432                     (DVRVertex **)realloc(seedVertices,
00433                                           maxSeedVerticesCount *
00434                                           sizeof(DVRVertex *)  );
00435             }
00436 
00437             seedVertices[seedVerticesCount++] = &_mfVertices[i];
00438         }
00439     } 
00440 }
00441 
00442 void DVRClipGeometry::linkContour(      DVRTriangle *startTriangle,
00443                                         Real32       dist2RefPlane,
00444                                   const Vec3f       &viewDir, 
00445                                         bool         positiveWinding)
00446 {
00447     FDEBUG(("DVRClipGeometry - linkcontour dist = %f\n", dist2RefPlane));
00448   
00449     bool closed = false;
00450 
00451     // first, we have to check for the correct winding direction.
00452 
00453     Pnt3f vertex[2];
00454     bool firstEdge;
00455     int  first = 0, second = 0;
00456 
00457     if(startTriangle->edgeCut[0] && startTriangle->edgeCut[1])
00458     {
00459         vertex[0] = interpolate(startTriangle, 1, 0, dist2RefPlane); 
00460         vertex[1] = interpolate(startTriangle, 1, 2, dist2RefPlane);
00461 
00462         first = 0; second = 1;
00463     }
00464     else if (startTriangle->edgeCut[1] && startTriangle->edgeCut[2])
00465     {
00466         vertex[0] = interpolate(startTriangle, 2, 1, dist2RefPlane);
00467         vertex[1] = interpolate(startTriangle, 2, 0, dist2RefPlane);
00468 
00469         first = 1; second = 2;
00470     }
00471     else if (startTriangle->edgeCut[0] && startTriangle->edgeCut[2])
00472     {
00473         vertex[0] = interpolate(startTriangle, 0, 1, dist2RefPlane);
00474         vertex[1] = interpolate(startTriangle, 0, 2, dist2RefPlane);
00475 
00476         first = 0; second = 2;
00477     }
00478 
00479     // Now we should have both cut points on our edges.
00480 
00481     // If the cross product of the normal of this triangle with the 
00482     // vector between the two cut points (cutPoint[1] - cutPoint[0]) 
00483     // has a positive dot product with the viewing direction, then 
00484     // the edge with cutPoint[0] on it is the right direction, otherwise
00485     // we would have to choose the other direction.
00486 
00487     Vec3f tmp = vertex[1] - vertex[0];
00488 
00489     tmp = tmp.cross(startTriangle->transformedNormal);
00490 
00491     if(tmp.dot(viewDir) <= 0.0)
00492     {
00493         firstEdge = false;
00494     }else
00495     {
00496         firstEdge = true;
00497     }
00498 
00499     if(!positiveWinding)
00500         firstEdge = !firstEdge;
00501 
00502     DVRTriangle *current = startTriangle;
00503 
00504     current->inContour = true;
00505 
00506     if(firstEdge)
00507     {
00508         current->cutPnt      = vertex[0];
00509         current->cutPoint[0] = vertex[0][0];
00510         current->cutPoint[1] = vertex[0][1];
00511         current->cutPoint[2] = vertex[0][2];
00512 
00513         current->contourNeighbour = &_mfTriangles[current->neighbours[first]];
00514 
00515         //      // debugging -> remove
00516         //      if(!current->contourNeighbour){
00517         //        std::cerr<<"contour neighbour is NULL\n";
00518         //        exit(0);
00519         //      }
00520 
00521         current = current->contourNeighbour;
00522     }
00523     else
00524     {
00525         current->cutPnt      = vertex[1];
00526         current->cutPoint[0] = vertex[1][0];
00527         current->cutPoint[1] = vertex[1][1];
00528         current->cutPoint[2] = vertex[1][2];    
00529 
00530         current->contourNeighbour = &_mfTriangles[current->neighbours[second]];
00531         //      // debugging -> remove
00532         //      if(!current->contourNeighbour){
00533         //        std::cerr<<"contour neighbour is NULL\n";
00534         //        exit(0);
00535         //      }
00536 
00537         current = current->contourNeighbour;    
00538     }
00539 
00540     //check neighbours
00541     while(!closed)
00542     {
00543         closed             = true;
00544         current->inContour = true;
00545 
00546         for(UInt32 i = 0; i < 3; i++)
00547         {
00548             // if a neighbour triangle is in the active triangle list and 
00549             // not yet in a contour it is our new contour neighbour.
00550             if( current->edgeCut[i] && 
00551                !_mfTriangles[current->neighbours[i]].inContour)
00552             {
00553                 // calculate cut point  
00554                 current->cutPnt = interpolate(current, 
00555                                               i, 
00556                                               (i + 1) % 3, 
00557                                               dist2RefPlane);
00558 
00559                 current->cutPoint[0] = current->cutPnt[0];
00560                 current->cutPoint[1] = current->cutPnt[1];
00561                 current->cutPoint[2] = current->cutPnt[2];
00562 
00563                 current->contourNeighbour = 
00564                     &_mfTriangles[current->neighbours[i]];
00565 
00566                 //      // debugging -> remove
00567                 //      if(!current->contourNeighbour){
00568                 //        std::cerr<<"contour neighbour is NULL\n";
00569                 //        exit(0);
00570                 //      }
00571 
00572                 current = current->contourNeighbour;
00573                 closed  = false;
00574 
00575                 break;
00576             }// !inContour
00577         } // end for neighbours
00578     } // end while !closed
00579 
00580     for(UInt32 i = 0; i < 3; i++)
00581     {
00582         if(&_mfTriangles[current->neighbours[i]] == startTriangle)
00583         {
00584             current->cutPnt = interpolate(current, 
00585                                           i, 
00586                                           (i + 1) % 3, 
00587                                           dist2RefPlane);
00588 
00589             current->cutPoint[0] = current->cutPnt[0];
00590             current->cutPoint[1] = current->cutPnt[1];
00591             current->cutPoint[2] = current->cutPnt[2];
00592 
00593             // now the ring is closed.
00594 
00595             current->contourNeighbour = startTriangle;
00596             //        // debugging -> remove
00597             //        if(!current->contourNeighbour){
00598             //      std::cerr<<"contour neighbour is NULL\n";
00599             //      exit(0);
00600             //        }
00601             break;
00602         }
00603     } // end for neighbours
00604 
00605     //    // debugging -> remove
00606     //    if(!current->contourNeighbour){
00607     //      std::cerr <<"contour could not closed\n";
00608     //      std::cerr <<current->edgeCut[0]<<current->edgeCut[1]
00609     //                <<current->edgeCut[2]<<std::endl;
00610     //      exit(0);
00611     //    }
00612 }
00613 
00614 void DVRClipGeometry::buildContours(      Real32  dist2RefPlane, 
00615                                           bool    positiveWinding, 
00616                                     const Vec3f  &sliceNormal    )
00617 {
00618     contours.clear();
00619 
00620     for(UInt32 i = 0; i < activeTrianglesCount; i++)
00621     { 
00622         DVRTriangle* currentTriangle = activeTriangles[i];
00623 
00624         // if the triangle is already in a contour we can skip it    
00625         if(!currentTriangle->inContour)
00626         {
00627             contours.push_back(currentTriangle);
00628             
00629             linkContour(currentTriangle, 
00630                         dist2RefPlane, 
00631                         sliceNormal, 
00632                         positiveWinding);
00633         }
00634     }
00635 }
00636 
00637 const DVRTriangleList &DVRClipGeometry::getContours(
00638           Real32  dist2RefPlane, 
00639           bool    positiveWinding, 
00640     const Vec3f  &sliceNormal    )
00641 {  
00642     if(!initialized) 
00643         return contours;
00644 
00645     // compute new active triangle set and for this slice 
00646     // and update seed vertex set
00647     updateActiveTriangles(dist2RefPlane, sliceNormal);
00648 
00649     // build contours from active triangle set
00650     buildContours(dist2RefPlane, positiveWinding, sliceNormal);
00651 
00652     return contours;
00653 }
00654 
00655 void DVRClipGeometry::addNewActiveTriangles(DVRVertex *vertex, 
00656                                             Real32     dist2RefPlane)
00657 {
00658     // iterate over triangles
00659     DVRVertex *switchedVertices[3];
00660   
00661     std::vector<Int32> &adjacentTriangles = vertex->adjacentTriangles; 
00662 
00663     UInt32 numAdjacenTriangles =  adjacentTriangles.size();
00664 
00665     for(UInt32 j = 0; j < numAdjacenTriangles; j++)
00666     {
00667         DVRTriangle *triangle = &_mfTriangles[adjacentTriangles[j]];
00668 
00669         if(!triangle->visited)
00670         {
00671             // insert triangle if it is cut and it was not visited so far...
00672             if(isCut(triangle,dist2RefPlane, switchedVertices)) 
00673             {
00674                 triangle->visited   = true;
00675                 triangle->inContour = false;
00676 
00677                 addActiveTriangle(triangle);
00678             }
00679             else
00680             { 
00681                 // neighbour triangle is not visited and not cut -> 
00682                 // check neighbours
00683 
00684                 triangle->visited   = true;
00685                 triangle->inContour = false;
00686             } 
00687       
00688             // check neighbours
00689             for(UInt32 i = 0; i < 3; i++)
00690             {
00691                 if(switchedVertices[i])
00692                 {
00693                     addNewActiveTriangles(switchedVertices[i],
00694                                           dist2RefPlane      );
00695                 }
00696             }       
00697         }
00698     }
00699 }
00700 
00701 void DVRClipGeometry::updateActiveTriangles(      Real32  dist2RefPlane,  
00702                                             const Vec3f  &             )
00703 {
00704     // first, we check the active triangles.
00705 
00706     DVRVertex *switchedVertices[3];
00707   
00708     for(Int32 triIt = activeTrianglesCount-1; triIt >= 0; triIt--)
00709     {
00710         DVRTriangle *tri = activeTriangles[triIt];
00711 
00712         tri->inContour        = false;
00713         tri->contourNeighbour = NULL;
00714 
00715         // if an active triangle is cut by the plane it simply stays in 
00716         // the list.otherwise we have to remove it and check the neighbour
00717         // triangles.
00718 
00719         if(!(isCut(tri,dist2RefPlane, switchedVertices)))
00720         {
00721             //remove triangle
00722             activeTrianglesCount--;
00723             activeTriangles[triIt] = activeTriangles[activeTrianglesCount];
00724         }
00725         
00726         // check triangles adjacent to the vertices that moved behind 
00727         // the active slice
00728 
00729         for(UInt32 i = 0; i < 3; i++)
00730         {
00731             if(switchedVertices[i])
00732                 addNewActiveTriangles(switchedVertices[i], dist2RefPlane);
00733         }
00734     }
00735 
00736     // now we have to check our seed set, if new triangles have to be added.
00737   
00738     // run over our seed set
00739     for(Int32 vertIt = seedVerticesCount-1; vertIt >= 0; vertIt--)
00740     {
00741         DVRVertex *sv = seedVertices[vertIt];
00742 
00743         // check if seed vertex has been hit by the plane
00744         if (sv->isBehindPlane(dist2RefPlane))
00745         {
00746             // add triangles to active triangle list      
00747             addNewActiveTriangles(sv,dist2RefPlane);
00748             
00749             // we will never need this seed vertex again, we can erase it 
00750             // from the list.
00751             seedVertices[vertIt] = seedVertices[--seedVerticesCount];
00752         }    
00753     }
00754 }
00755 
00756 //
00757 void DVRClipGeometry::addActiveTriangle(DVRTriangle *tri)
00758 {
00759     if(maxActiveTrianglesCount <= activeTrianglesCount)
00760     {
00761         FDEBUG(("realloc active tri list\n"));
00762         // allocate additional mem (TODO: better prediction for needed mem)
00763 
00764         maxActiveTrianglesCount *= 2;
00765         activeTriangles          = 
00766             (DVRTriangle **) realloc(activeTriangles, 
00767                                      sizeof(DVRTriangle *) * 
00768                                      maxActiveTrianglesCount);
00769     }
00770     
00771     activeTriangles[activeTrianglesCount] = tri;    
00772 
00773     activeTrianglesCount++;
00774 }
00775 
00776 bool DVRClipGeometry::setNumAddPerVertexAttr(
00777     UInt32 additionalPerVertexAttributes)
00778 {
00779     UInt32 numTriangles = _mfTriangles.size();
00780 
00781     // update triangles
00782     for(UInt32 i = 0; i < numTriangles; i++)
00783     {
00784         if(!_mfTriangles[i].setNumAddPerVertexAttr(
00785                additionalPerVertexAttributes))
00786         {
00787             return false;
00788         }
00789     }
00790 
00791     return true;
00792 }
00793 
00794 //  // debugging -> remove
00795 //  void DVRClipGeometry::correct()
00796 //  {
00797 //    for(UInt32 i = 0; i < _mfTriangles.size(); i++){  
00798 //      _mfTriangles[i].correct();    
00799 //    }
00800 //    for(UInt32 i = 0; i < _mfVertices.size(); i++){
00801 //      _mfVertices[i].correct();
00802 //    }
00803 //  }
00804 
00805 
00806 
00807 /*------------------------------------------------------------------------*/
00808 /*                              cvs id's                                  */
00809 
00810 #ifdef OSG_SGI_CC
00811 #pragma set woff 1174
00812 #endif
00813 
00814 #ifdef OSG_LINUX_ICC
00815 #pragma warning( disable : 177 )
00816 #endif
00817 
00818 namespace
00819 {
00820     static Char8 cvsid_cpp       [] = "@(#)$Id: $";
00821     static Char8 cvsid_hpp       [] = OSGDVRCLIPGEOMETRYBASE_HEADER_CVSID;
00822     static Char8 cvsid_inl       [] = OSGDVRCLIPGEOMETRYBASE_INLINE_CVSID;
00823 
00824     static Char8 cvsid_fields_hpp[] = OSGDVRCLIPGEOMETRYFIELDS_HEADER_CVSID;
00825 }
00826 
00827 #ifdef __sgi
00828 #pragma reset woff 1174
00829 #endif
00830 

Generated on Thu Aug 25 04:03:15 2005 for OpenSG by  doxygen 1.4.3