#include <OSGDVRClipper.h>
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 Plane & | getReferencePlane () const |
| bool | setNumAddPerVertexAttr (DVRVolume *volume, UInt32 additionalPerVertexAttributes) |
| set the number of additional per vertex attributes | |
Private Attributes | |
| bool | hasTesselatorSupport |
| GLUtesselator available? | |
| GLdouble * | sliceVertexData |
| Plane | refPlane |
| UInt32 | numAddPerVertexAttr |
Definition at line 13 of file OSGDVRClipper.h.
| 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 = (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 }
| void DVRClipper::clipSlice | ( | DVRVolume * | volume, | |
| DVRSlice & | slice, | |||
| const Vec3f & | slicingNormal, | |||
| Real32 | dist2RefPlane, | |||
| DVRRenderSlice & | clippedSlice | |||
| ) |
Definition at line 187 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::PointInterface< ValueTypeT, StorageInterfaceT >::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().
00192 { 00193 const Vec3f &texScale = unclippedSlice.getTextureScale (); 00194 const Vec3f &texTranslate = unclippedSlice.getTextureTranslate(); 00195 00196 // get clip objects 00197 DVRClipObjectsPtr clipObjects = DVRVOLUME_PARAMETER(volume, 00198 DVRClipObjects); 00199 00200 // nothing to clip with? 00201 if(clipObjects == NullFC) 00202 { 00203 DVRRenderSlicePrimitive *newPrimitive = new DVRRenderSlicePrimitive(); 00204 00205 newPrimitive->type = GL_TRIANGLE_FAN; 00206 00207 for(UInt32 i = 0; i < unclippedSlice.getVertexCount(); i++) 00208 { 00209 UInt32 idx = (6+numAddPerVertexAttr)*i; 00210 sliceVertexData[idx ] = 00211 unclippedSlice.getVertex(i).getValues()[0]; 00212 00213 sliceVertexData[idx + 1] = 00214 unclippedSlice.getVertex(i).getValues()[1]; 00215 00216 sliceVertexData[idx + 2] = 00217 unclippedSlice.getVertex(i).getValues()[2]; 00218 00219 00220 // set (standard) texture coordinates 00221 sliceVertexData[idx + 3] = 00222 texScale[0] * 00223 unclippedSlice.getVertex(i).getValues()[0] + 00224 texTranslate[0]; 00225 00226 sliceVertexData[idx + 4] = 00227 texScale[1] * 00228 unclippedSlice.getVertex(i).getValues()[1] + 00229 texTranslate[1]; 00230 00231 sliceVertexData[idx + 5] = 00232 texScale[2] * 00233 unclippedSlice.getVertex(i).getValues()[2] + 00234 texTranslate[2]; 00235 00236 newPrimitive->vertices.push_back(&sliceVertexData[idx]); 00237 } 00238 00239 clippedSlice.push_back(newPrimitive); 00240 00241 return; 00242 } 00243 00244 if(!hasTesselatorSupport) 00245 return; 00246 00247 // render colored contours only (usefull for debugging) 00248 if(clipObjects->getDoContours()) 00249 { 00250 glDisable(GL_TEXTURE ); 00251 glDisable(GL_LIGHTING ); 00252 00253 glBegin (GL_LINE_STRIP); 00254 { 00255 int col = 0; 00256 00257 for(UInt32 i = 0; i < unclippedSlice.getVertexCount(); i++) 00258 { 00259 glColor3f(col % 3 == 0 ? 1.0f : 0.0f, 00260 col % 3 == 1 ? 1.0f : 0.0f, 00261 col % 3 == 2 ? 1.0f : 0.0f); 00262 00263 col++; 00264 00265 glVertex3fv(unclippedSlice.getVertex(i).getValues()); 00266 } 00267 } 00268 glEnd(); 00269 00270 bool clipAwayOutside = 00271 clipObjects->getClipMode() == DVRClipObjects::Difference; 00272 00273 for(UInt32 i = 0; i < clipObjects->count(); i++) 00274 { 00275 // get i-th clip object 00276 DVRClipGeometryPtr clipObject = clipObjects->get(i); 00277 00278 // compute the contours of the triangles intersecting the 00279 // current slice 00280 00281 const DVRTriangleList &contours = 00282 clipObject->getContours(dist2RefPlane, 00283 !clipAwayOutside, 00284 slicingNormal); 00285 00286 if(!contours.empty()) 00287 { 00288 DVRTriangle *current; 00289 DVRTriangle *contourStart; 00290 00291 // iterate over all contours 00292 DVRTriangleList::const_iterator contoursIt; 00293 00294 for(contoursIt = contours.begin(); 00295 contoursIt != contours.end (); 00296 contoursIt++) 00297 { 00298 contourStart = current = *contoursIt; 00299 00300 glBegin(GL_LINE_STRIP); 00301 { 00302 int col = 0; 00303 00304 // iterate over all triangles in the current contour 00305 do 00306 { 00307 glColor3f(col % 3 == 0 ? 1.0f : 0.0f, 00308 col % 3 == 1 ? 1.0f : 0.0f, 00309 col % 3 == 2 ? 1.0f : 0.0f); 00310 00311 col++; 00312 00313 glVertex3dv(current->cutPoint); 00314 00315 current = current->contourNeighbour; 00316 00317 } while(current!= contourStart); 00318 } 00319 glEnd(); 00320 } 00321 } 00322 } 00323 00324 glEnable(GL_TEXTURE ); 00325 glEnable(GL_LIGHTING); 00326 00327 } 00328 else 00329 { 00330 // tesselate and render the clipped slices 00331 00332 // set the slice normal for tesselation 00333 gluTessNormal(myTess, 00334 slicingNormal[0], 00335 slicingNormal[1], 00336 slicingNormal[2]); 00337 00338 clippedSlice.clear(); 00339 00340 gluTessBeginPolygon(myTess, &clippedSlice); 00341 00342 // set the slice's base contour 00343 gluTessBeginContour(myTess); 00344 00345 for(UInt32 i = 0; i < unclippedSlice.getVertexCount(); i++) 00346 { 00347 UInt32 idx = (6 + numAddPerVertexAttr) * i; 00348 00349 sliceVertexData[idx ] = 00350 unclippedSlice.getVertex(i).getValues()[0]; 00351 00352 sliceVertexData[idx + 1] = 00353 unclippedSlice.getVertex(i).getValues()[1]; 00354 00355 sliceVertexData[idx + 2] = 00356 unclippedSlice.getVertex(i).getValues()[2]; 00357 00358 // set (standard) texture coordinates 00359 sliceVertexData[idx + 3] = 00360 texScale[0] * 00361 unclippedSlice.getVertex(i).getValues()[0] + 00362 texTranslate[0]; 00363 00364 sliceVertexData[idx + 4] = 00365 texScale[1] * 00366 unclippedSlice.getVertex(i).getValues()[1] + 00367 texTranslate[1]; 00368 00369 sliceVertexData[idx + 5] = 00370 texScale[2] * 00371 unclippedSlice.getVertex(i).getValues()[2] + 00372 texTranslate[2]; 00373 00374 gluTessVertex(myTess, 00375 &sliceVertexData[idx], 00376 &sliceVertexData[idx]); 00377 } 00378 00379 gluTessEndContour(myTess); 00380 00381 // set contours of clip objects 00382 if(clipObjects->getClipMode() != DVRClipObjects::Off) 00383 { 00384 // get clip mode 00385 bool clipAwayOutside = 00386 clipObjects->getClipMode() == DVRClipObjects::Difference; 00387 00388 // add the contours of the intersections of the clip geometries 00389 // with the slice 00390 for(UInt32 i = 0; i < clipObjects->count(); i++) 00391 { 00392 // get i-th clip object 00393 DVRClipGeometryPtr clipObject = clipObjects->get(i); 00394 00395 // compute the contours of the triangles intersecting 00396 // the current slice 00397 00398 const DVRTriangleList &contours = 00399 clipObject->getContours( dist2RefPlane, 00400 !clipAwayOutside, 00401 slicingNormal); 00402 00403 if(!contours.empty()) 00404 { 00405 DVRTriangle *current; 00406 DVRTriangle *contourStart; 00407 00408 // iterate over all contours 00409 DVRTriangleList::const_iterator contoursIt; 00410 00411 for(contoursIt = contours.begin(); 00412 contoursIt != contours.end (); 00413 contoursIt++) 00414 { 00415 contourStart = current = *contoursIt; 00416 00417 // start new contour 00418 gluTessBeginContour(myTess); 00419 00420 // iterate over all triangles in the current contour 00421 do 00422 { 00423 // set (standard) texture coordinates 00424 current->cutPoint[3] = 00425 texScale[0] * 00426 current->cutPoint[0] + 00427 texTranslate[0]; 00428 00429 current->cutPoint[4] = 00430 texScale[1] * 00431 current->cutPoint[1] + 00432 texTranslate[1]; 00433 00434 current->cutPoint[5] = 00435 texScale[2] * 00436 current->cutPoint[2] + 00437 texTranslate[2]; 00438 00439 if(!current->cutPoint) 00440 std::cerr << "WTF: cutPoint is NULL" 00441 << std::endl; 00442 00443 gluTessVertex(myTess, 00444 current->cutPoint, 00445 current->cutPoint); 00446 00447 current = current->contourNeighbour; 00448 00449 } while(current != contourStart); 00450 00451 gluTessEndContour(myTess); 00452 } 00453 } 00454 } 00455 } 00456 00457 gluTessEndPolygon(myTess); 00458 } 00459 }
| 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 = (atof((char*)gluGetString(GLU_VERSION)) >= 1.2); 00116 00117 if(!hasTesselatorSupport) 00118 return; 00119 } 00120 00121 if(myTess == NULL) 00122 { 00123 myTess = gluNewTess(); 00124 00125 // registering callback functions for glu tesselator... 00126 gluTessCallback(myTess, 00127 GLU_TESS_COMBINE_DATA, 00128 reinterpret_cast<OSGGLUfuncptr>(vertexCombineCallback)); 00129 00130 gluTessCallback(myTess, 00131 GLU_TESS_VERTEX_DATA, 00132 reinterpret_cast<OSGGLUfuncptr>(vertexCallback)); 00133 00134 gluTessCallback(myTess, 00135 GLU_TESS_BEGIN_DATA, 00136 reinterpret_cast<OSGGLUfuncptr>(beginCallback)); 00137 00138 gluTessCallback(myTess, 00139 GLU_TESS_END_DATA, 00140 reinterpret_cast<OSGGLUfuncptr>(endCallback)); 00141 00142 gluTessCallback(myTess, 00143 GLU_TESS_ERROR, 00144 reinterpret_cast<OSGGLUfuncptr>(errorCallback)); 00145 00146 } 00147 00148 }
| void DVRClipper::reset | ( | DVRVolume * | volume | ) |
Definition at line 150 of file OSGDVRClipper.cpp.
References DVRVOLUME_PARAMETER, hasTesselatorSupport, osg::DVRClipObjects::Intersection, and osg::NullFC.
Referenced by osg::DVRVolume::draw(), and osg::Brick::render3DSlices().
00151 { 00152 if(volume == NULL || !hasTesselatorSupport) 00153 return; 00154 00155 // get clip objects 00156 DVRClipObjectsPtr clipObjects = DVRVOLUME_PARAMETER(volume, 00157 DVRClipObjects); 00158 00159 if(clipObjects == NullFC) 00160 return; 00161 00162 // set tesselator properties according to clip mode 00163 if(clipObjects->getClipMode() == DVRClipObjects::Intersection) 00164 { 00165 gluTessProperty(myTess, 00166 GLU_TESS_WINDING_RULE, 00167 GLU_TESS_WINDING_ABS_GEQ_TWO); 00168 } 00169 else 00170 { 00171 gluTessProperty(myTess, 00172 GLU_TESS_WINDING_RULE, 00173 GLU_TESS_WINDING_POSITIVE); 00174 } 00175 00176 // reset local data 00177 for(UInt32 i = 0; i < clipObjects->count(); i++) 00178 { 00179 // reset i-th clip object 00180 DVRClipGeometryPtr clipObject = clipObjects->get(i); 00181 00182 clipObject->resetLocalData (); 00183 clipObject->computeSeedVertices(); 00184 } 00185 }
| 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 = (GLdouble*) realloc( 00076 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 }
bool osg::DVRClipper::hasTesselatorSupport [private] |
Definition at line 53 of file OSGDVRClipper.h.
Referenced by clipSlice(), DVRClipper(), initialize(), and reset().
GLdouble* osg::DVRClipper::sliceVertexData [private] |
Definition at line 62 of file OSGDVRClipper.h.
Referenced by clipSlice(), DVRClipper(), setNumAddPerVertexAttr(), and ~DVRClipper().
Plane osg::DVRClipper::refPlane [private] |
Definition at line 65 of file OSGDVRClipper.h.
Referenced by getReferencePlane(), and setReferencePlane().
UInt32 osg::DVRClipper::numAddPerVertexAttr [private] |
Definition at line 68 of file OSGDVRClipper.h.
Referenced by clipSlice(), DVRClipper(), and setNumAddPerVertexAttr().
1.5.5