osg::DVRClipper Class Reference

#include <OSGDVRClipper.h>

List of all members.

Public Member Functions

 DVRClipper (void)
 ~DVRClipper (void)
void clipSlice (DVRVolume *volume, DVRSlice &slice, const Vec3f &slicingNormal, Real32 dist2RefPlane, DVRRenderSlice &clippedSlice)
 clips the slice
void initialize (DVRVolume *volume)
 initialize the clipper
void reset (DVRVolume *volume)
 Reset objects state.
void setReferencePlane (const Plane &refPlane)
const PlanegetReferencePlane () const
bool setNumAddPerVertexAttr (DVRVolume *volume, UInt32 additionalPerVertexAttributes)
 set the number of additional per vertex attributes

Private Attributes

bool hasTesselatorSupport
 GLUtesselator available?
GLdoublesliceVertexData
Plane refPlane
UInt32 numAddPerVertexAttr

Detailed Description

Definition at line 13 of file OSGDVRClipper.h.


Constructor & Destructor Documentation

DVRClipper::DVRClipper ( void   ) 

Definition at line 28 of file OSGDVRClipper.cpp.

References GLdouble, hasTesselatorSupport, numAddPerVertexAttr, and sliceVertexData.

00029 {
00030     myTess = NULL;
00031     // allocate temp. storage for 6 vertex positions and texture coordinates
00032     sliceVertexData = static_cast<GLdouble*>(malloc(6*6*sizeof(GLdouble)));
00033 
00034     numAddPerVertexAttr  = 0;
00035     hasTesselatorSupport = false;
00036 }

DVRClipper::~DVRClipper ( void   ) 

Definition at line 38 of file OSGDVRClipper.cpp.

References sliceVertexData.

00039 {
00040     if(myTess)
00041         gluDeleteTess(myTess);
00042 
00043     free(sliceVertexData);
00044 }


Member Function Documentation

void DVRClipper::clipSlice ( DVRVolume volume,
DVRSlice slice,
const Vec3f slicingNormal,
Real32  dist2RefPlane,
DVRRenderSlice clippedSlice 
)

Definition at line 189 of file OSGDVRClipper.cpp.

References osg::DVRRenderSlice::clear(), osg::DVRTriangle::contourNeighbour, osg::DVRTriangle::cutPoint, osg::DVRClipObjects::Difference, DVRVOLUME_PARAMETER, osg::DVRSlice::getTextureScale(), osg::DVRSlice::getTextureTranslate(), osg::Point< ValueTypeT, SizeI >::getValues(), osg::DVRSlice::getVertex(), osg::DVRSlice::getVertexCount(), hasTesselatorSupport, osg::NullFC, numAddPerVertexAttr, osg::DVRClipObjects::Off, sliceVertexData, osg::DVRRenderSlicePrimitive::type, and osg::DVRRenderSlicePrimitive::vertices.

Referenced by osg::Brick::render2DSliceXY(), osg::Brick::render2DSliceXZ(), osg::Brick::render2DSliceYZ(), and osg::Brick::render3DSlices().

00194 {
00195     const Vec3f &texScale     = unclippedSlice.getTextureScale    ();
00196     const Vec3f &texTranslate = unclippedSlice.getTextureTranslate();
00197 
00198     // get clip objects
00199     DVRClipObjectsPtr clipObjects = DVRVOLUME_PARAMETER(volume, 
00200                                                         DVRClipObjects);
00201 
00202     // nothing to clip with?
00203     if(clipObjects == NullFC)
00204     {
00205         DVRRenderSlicePrimitive *newPrimitive =  new DVRRenderSlicePrimitive();
00206 
00207         newPrimitive->type = GL_TRIANGLE_FAN;
00208 
00209         for(UInt32 i = 0; i < unclippedSlice.getVertexCount(); i++)
00210         {
00211             UInt32 idx = (6+numAddPerVertexAttr)*i;
00212             sliceVertexData[idx    ] = 
00213                 unclippedSlice.getVertex(i).getValues()[0];
00214 
00215             sliceVertexData[idx + 1] = 
00216                 unclippedSlice.getVertex(i).getValues()[1];
00217 
00218             sliceVertexData[idx + 2] =
00219                 unclippedSlice.getVertex(i).getValues()[2];
00220 
00221 
00222             // set (standard) texture coordinates
00223             sliceVertexData[idx + 3] = 
00224                 texScale[0] * 
00225                 unclippedSlice.getVertex(i).getValues()[0] + 
00226                 texTranslate[0];
00227 
00228             sliceVertexData[idx + 4] = 
00229                 texScale[1] * 
00230                 unclippedSlice.getVertex(i).getValues()[1] + 
00231                 texTranslate[1];
00232 
00233             sliceVertexData[idx + 5] = 
00234                 texScale[2] * 
00235                 unclippedSlice.getVertex(i).getValues()[2] + 
00236                 texTranslate[2];      
00237 
00238             newPrimitive->vertices.push_back(&sliceVertexData[idx]);
00239         }
00240 
00241         clippedSlice.push_back(newPrimitive);
00242         
00243         return;
00244     }
00245 
00246     if(!hasTesselatorSupport)
00247         return;
00248 
00249     // render colored contours only (usefull for debugging)
00250     if(clipObjects->getDoContours())
00251     {
00252         glDisable(GL_TEXTURE   );
00253         glDisable(GL_LIGHTING  );
00254 
00255         glBegin  (GL_LINE_STRIP);  
00256         {
00257             int col = 0;
00258             
00259             for(UInt32 i = 0; i < unclippedSlice.getVertexCount(); i++)
00260             {      
00261                 glColor3f(col % 3 == 0 ? 1.0f : 0.0f, 
00262                           col % 3 == 1 ? 1.0f : 0.0f, 
00263                           col % 3 == 2 ? 1.0f : 0.0f);
00264                 
00265                 col++;
00266                 
00267                 glVertex3fv(unclippedSlice.getVertex(i).getValues());
00268             }
00269         }
00270         glEnd();
00271    
00272         bool clipAwayOutside = 
00273             clipObjects->getClipMode() == DVRClipObjects::Difference;
00274     
00275         for(UInt32 i = 0; i < clipObjects->count(); i++)
00276         {
00277             // get i-th clip object
00278             DVRClipGeometryPtr clipObject = clipObjects->get(i);
00279       
00280             // compute the contours of the triangles intersecting the 
00281             // current slice
00282 
00283             const DVRTriangleList &contours = 
00284                 clipObject->getContours(dist2RefPlane,
00285                                         !clipAwayOutside,
00286                                         slicingNormal);     
00287       
00288             if(!contours.empty())
00289             {
00290                 DVRTriangle *current;
00291                 DVRTriangle *contourStart;
00292     
00293                 // iterate over all contours
00294                 DVRTriangleList::const_iterator contoursIt;
00295 
00296                 for(contoursIt  = contours.begin(); 
00297                     contoursIt != contours.end  (); 
00298                     contoursIt++)
00299                 { 
00300                     contourStart = current = *contoursIt;    
00301       
00302                     glBegin(GL_LINE_STRIP);   
00303                     {
00304                         int col = 0;
00305                         
00306                         // iterate over all triangles in the current contour
00307                         do
00308                         {              
00309                             glColor3f(col % 3 == 0 ? 1.0f : 0.0f, 
00310                                       col % 3 == 1 ? 1.0f : 0.0f, 
00311                                       col % 3 == 2 ? 1.0f : 0.0f);
00312 
00313                             col++;
00314 
00315                             glVertex3dv(current->cutPoint);
00316 
00317                             current = current->contourNeighbour;
00318 
00319                         } while(current!= contourStart);
00320                     }
00321                     glEnd();
00322                 }
00323             }
00324         }
00325         
00326         glEnable(GL_TEXTURE );
00327         glEnable(GL_LIGHTING);
00328         
00329     }
00330     else
00331     {
00332         // tesselate and render the clipped slices
00333 
00334         // set the slice normal for tesselation
00335         gluTessNormal(myTess, 
00336                       slicingNormal[0], 
00337                       slicingNormal[1], 
00338                       slicingNormal[2]);    
00339         
00340         clippedSlice.clear();
00341         
00342         gluTessBeginPolygon(myTess, &clippedSlice);
00343     
00344         // set the slice's base contour
00345         gluTessBeginContour(myTess);
00346         
00347         for(UInt32 i = 0; i < unclippedSlice.getVertexCount(); i++)
00348         {       
00349             UInt32 idx = (6 + numAddPerVertexAttr) * i;
00350 
00351             sliceVertexData[idx    ] = 
00352                 unclippedSlice.getVertex(i).getValues()[0];
00353 
00354             sliceVertexData[idx + 1] = 
00355                 unclippedSlice.getVertex(i).getValues()[1];
00356 
00357             sliceVertexData[idx + 2] = 
00358                 unclippedSlice.getVertex(i).getValues()[2];
00359 
00360             // set (standard) texture coordinates
00361             sliceVertexData[idx + 3] = 
00362                 texScale[0] *
00363                 unclippedSlice.getVertex(i).getValues()[0] + 
00364                 texTranslate[0];
00365 
00366             sliceVertexData[idx + 4] = 
00367                 texScale[1] * 
00368                 unclippedSlice.getVertex(i).getValues()[1] + 
00369                 texTranslate[1];
00370 
00371             sliceVertexData[idx + 5] = 
00372                 texScale[2] * 
00373                 unclippedSlice.getVertex(i).getValues()[2] +
00374                 texTranslate[2];
00375 
00376             gluTessVertex(myTess, 
00377                           &sliceVertexData[idx], 
00378                           &sliceVertexData[idx]);
00379         }
00380         
00381         gluTessEndContour(myTess);
00382         
00383         // set contours of clip objects
00384         if(clipObjects->getClipMode() != DVRClipObjects::Off)
00385         {
00386             // get clip mode
00387             bool clipAwayOutside = 
00388                 clipObjects->getClipMode() == DVRClipObjects::Difference;
00389       
00390             // add the contours of the intersections of the clip geometries 
00391             // with the slice
00392             for(UInt32 i = 0; i < clipObjects->count(); i++)
00393             {
00394                 // get i-th clip object
00395                 DVRClipGeometryPtr clipObject = clipObjects->get(i);
00396     
00397                 // compute the contours of the triangles intersecting 
00398                 // the current slice
00399 
00400                 const DVRTriangleList &contours = 
00401                     clipObject->getContours( dist2RefPlane,
00402                                             !clipAwayOutside,
00403                                              slicingNormal);       
00404     
00405                 if(!contours.empty())
00406                 {
00407                     DVRTriangle *current;
00408                     DVRTriangle *contourStart;
00409       
00410                     // iterate over all contours
00411                     DVRTriangleList::const_iterator contoursIt;
00412 
00413                     for(contoursIt  = contours.begin(); 
00414                         contoursIt != contours.end  (); 
00415                         contoursIt++)
00416                     { 
00417                         contourStart = current = *contoursIt;
00418                 
00419                         // start new contour
00420                         gluTessBeginContour(myTess);
00421         
00422                         // iterate over all triangles in the current contour
00423                         do
00424                         {       
00425                             // set (standard) texture coordinates
00426                             current->cutPoint[3] = 
00427                                 texScale[0] * 
00428                                 current->cutPoint[0] + 
00429                                 texTranslate[0];
00430 
00431                             current->cutPoint[4] = 
00432                                 texScale[1] * 
00433                                 current->cutPoint[1] + 
00434                                 texTranslate[1];
00435 
00436                             current->cutPoint[5] = 
00437                                 texScale[2] * 
00438                                 current->cutPoint[2] + 
00439                                 texTranslate[2];
00440 
00441                             if(!current->cutPoint)
00442                                 std::cerr << "WTF: cutPoint is NULL"
00443                                           << std::endl;
00444 
00445                             gluTessVertex(myTess, 
00446                                           current->cutPoint, 
00447                                           current->cutPoint);
00448 
00449                             current = current->contourNeighbour;
00450 
00451                         } while(current != contourStart);
00452         
00453                         gluTessEndContour(myTess);
00454                     }
00455                 }
00456             }
00457         }
00458         
00459         gluTessEndPolygon(myTess);
00460     }
00461 }

void DVRClipper::initialize ( DVRVolume volume  ) 

Definition at line 100 of file OSGDVRClipper.cpp.

References beginCallback(), DVRVOLUME_PARAMETER, endCallback(), errorCallback(), hasTesselatorSupport, osg::NullFC, vertexCallback(), and vertexCombineCallback().

Referenced by osg::DVRVolume::draw().

00101 {
00102     if(volume == NULL)
00103         return;
00104  
00105     // get clip objects
00106     DVRClipObjectsPtr clipObjects = DVRVOLUME_PARAMETER(volume, 
00107                                                         DVRClipObjects);
00108   
00109     if(clipObjects == NullFC)
00110         return;
00111   
00112     if(!hasTesselatorSupport)
00113     {
00114         // check for glu tesselator support
00115         hasTesselatorSupport = 
00116             (atof(reinterpret_cast<const char*>(
00117                       gluGetString(GLU_VERSION))) >= 1.2);
00118         
00119         if(!hasTesselatorSupport)
00120             return;
00121     }
00122 
00123     if(myTess == NULL)
00124     {
00125         myTess = gluNewTess();
00126 
00127         // registering callback functions for glu tesselator...
00128         gluTessCallback(myTess, 
00129                         GLU_TESS_COMBINE_DATA, 
00130                         reinterpret_cast<OSGGLUfuncptr>(vertexCombineCallback));
00131 
00132         gluTessCallback(myTess, 
00133                         GLU_TESS_VERTEX_DATA, 
00134                         reinterpret_cast<OSGGLUfuncptr>(vertexCallback));
00135 
00136         gluTessCallback(myTess, 
00137                         GLU_TESS_BEGIN_DATA,
00138                         reinterpret_cast<OSGGLUfuncptr>(beginCallback));
00139 
00140         gluTessCallback(myTess, 
00141                         GLU_TESS_END_DATA, 
00142                         reinterpret_cast<OSGGLUfuncptr>(endCallback));
00143 
00144         gluTessCallback(myTess, 
00145                         GLU_TESS_ERROR, 
00146                         reinterpret_cast<OSGGLUfuncptr>(errorCallback));
00147     
00148     }
00149   
00150 }

void DVRClipper::reset ( DVRVolume volume  ) 

Definition at line 152 of file OSGDVRClipper.cpp.

References DVRVOLUME_PARAMETER, hasTesselatorSupport, osg::DVRClipObjects::Intersection, and osg::NullFC.

Referenced by osg::DVRVolume::draw(), and osg::Brick::render3DSlices().

00153 {
00154     if(volume == NULL || !hasTesselatorSupport)
00155         return;
00156  
00157     // get clip objects
00158     DVRClipObjectsPtr clipObjects = DVRVOLUME_PARAMETER(volume, 
00159                                                         DVRClipObjects);
00160   
00161     if(clipObjects == NullFC)
00162         return;
00163   
00164     // set tesselator properties according to clip mode
00165     if(clipObjects->getClipMode() == DVRClipObjects::Intersection)
00166     {
00167         gluTessProperty(myTess, 
00168                         GLU_TESS_WINDING_RULE, 
00169                         GLU_TESS_WINDING_ABS_GEQ_TWO);
00170     }
00171     else
00172     {
00173         gluTessProperty(myTess, 
00174                         GLU_TESS_WINDING_RULE, 
00175                         GLU_TESS_WINDING_POSITIVE);
00176     }
00177   
00178     // reset local data
00179     for(UInt32 i = 0; i < clipObjects->count(); i++)
00180     {    
00181         // reset i-th clip object
00182         DVRClipGeometryPtr clipObject = clipObjects->get(i);
00183 
00184         clipObject->resetLocalData     ();  
00185         clipObject->computeSeedVertices();
00186     }
00187 }

void DVRClipper::setReferencePlane ( const Plane refPlane  ) 

Definition at line 46 of file OSGDVRClipper.cpp.

References FDEBUG, osg::Plane::getDistanceFromOrigin(), osg::Plane::getNormal(), refPlane, and osg::Plane::set().

Referenced by osg::DVRVolume::initializeClipObjects().

00047 {
00048     FDEBUG(("pre DVRVolume::setRefPlane - %f %f %f : %f\n",
00049             rP.getNormal()[0], 
00050             rP.getNormal()[1], 
00051             rP.getNormal()[2], 
00052             rP.getDistanceFromOrigin()));
00053 
00054     refPlane.set(rP.getNormal(), rP.getDistanceFromOrigin());
00055     
00056     FDEBUG(("post DVRVolume::setRefPlane - %f %f %f : %f\n",
00057             refPlane.getNormal()[0], 
00058             refPlane.getNormal()[1], 
00059             refPlane.getNormal()[2], 
00060             refPlane.getDistanceFromOrigin()));
00061 }

const Plane & DVRClipper::getReferencePlane (  )  const

Definition at line 63 of file OSGDVRClipper.cpp.

References refPlane.

Referenced by osg::Brick::render2DSliceXY(), osg::Brick::render2DSliceXZ(), and osg::Brick::render2DSliceYZ().

00064 {
00065     return refPlane;
00066 }

bool DVRClipper::setNumAddPerVertexAttr ( DVRVolume volume,
UInt32  additionalPerVertexAttributes 
)

basically there are two attributes available, the vertex position and a 3D texture coordinate. If one needs additional attributes, e.g. color, texture coordinates,.., the number of (double) values needed has to be set with this function.

Definition at line 69 of file OSGDVRClipper.cpp.

References DVRVOLUME_PARAMETER, GLdouble, osg::NullFC, numAddPerVertexAttr, and sliceVertexData.

00072 {
00073     numAddPerVertexAttr = additionalPerVertexAttributes;
00074 
00075     sliceVertexData = static_cast<GLdouble*>(
00076         realloc(sliceVertexData,
00077                 6 * (6 + additionalPerVertexAttributes) * sizeof(GLdouble)));
00078   
00079     if(!sliceVertexData)
00080         return false;
00081 
00082     // get clip objects
00083     DVRClipObjectsPtr clipObjects = DVRVOLUME_PARAMETER(volume, 
00084                                                         DVRClipObjects);
00085   
00086     if(clipObjects == NullFC)
00087         return true;
00088 
00089     for(UInt32 i = 0; i < clipObjects->count(); i++)
00090     {    
00091         DVRClipGeometryPtr clipObject = clipObjects->get(i);
00092 
00093         if(!clipObject->setNumAddPerVertexAttr(additionalPerVertexAttributes))
00094             return false;      
00095     }  
00096     return true;
00097 }


Member Data Documentation

Definition at line 53 of file OSGDVRClipper.h.

Referenced by clipSlice(), DVRClipper(), initialize(), and reset().

Definition at line 62 of file OSGDVRClipper.h.

Referenced by clipSlice(), DVRClipper(), setNumAddPerVertexAttr(), and ~DVRClipper().

Definition at line 65 of file OSGDVRClipper.h.

Referenced by getReferencePlane(), and setReferencePlane().

Definition at line 68 of file OSGDVRClipper.h.

Referenced by clipSlice(), DVRClipper(), and setNumAddPerVertexAttr().


The documentation for this class was generated from the following files:

Generated on 8 Feb 2010 for OpenSG by  doxygen 1.6.1