#include <OSGDisplayCalibration.h>
Inheritance diagram for osg::DisplayCalibration:

Definition at line 69 of file OSGDisplayCalibration.h.
|
|
Reimplemented from osg::DisplayCalibrationBase. Definition at line 73 of file OSGDisplayCalibration.h. |
|
|
Definition at line 98 of file OSGDisplayCalibrationBase.h. |
|
|
Reimplemented from osg::AttachmentContainer. Definition at line 100 of file OSGDisplayCalibrationBase.h. 00101 { 00102 EnabledFieldId = Inherited::NextFieldId, 00103 ServerFieldId = EnabledFieldId + 1, 00104 ColorMatrixFieldId = ServerFieldId + 1, 00105 GammaFieldId = ColorMatrixFieldId + 1, 00106 GammaRampFieldId = GammaFieldId + 1, 00107 GridWidthFieldId = GammaRampFieldId + 1, 00108 GridHeightFieldId = GridWidthFieldId + 1, 00109 GridFieldId = GridHeightFieldId + 1, 00110 ScaleDownFieldId = GridFieldId + 1, 00111 NextFieldId = ScaleDownFieldId + 1 00112 };
|
|
|
Definition at line 85 of file OSGDisplayCalibration.cpp. 00085 : 00086 Inherited(), 00087 _changed(true), 00088 _cmPort(NullFC), 00089 _dsPort(NullFC), 00090 _dsPort2(NullFC) 00091 { 00092 }
|
|
|
Definition at line 94 of file OSGDisplayCalibration.cpp. 00094 : 00095 Inherited(source), 00096 _changed(true), 00097 _cmPort(NullFC), 00098 _dsPort(NullFC), 00099 _dsPort2(NullFC) 00100 { 00101 }
|
|
|
Definition at line 103 of file OSGDisplayCalibration.cpp. References _cam, _cmPort, _cmRoot, _ds2Back, _ds2Root, _dsBack, _dsPort, _dsPort2, _dsRoot, osg::NullFC, and osg::subRefCP(). 00104 { 00105 if(_cmPort != osg::NullFC) 00106 { 00107 subRefCP(_cmPort); 00108 subRefCP(_dsPort); 00109 subRefCP(_dsPort2); 00110 subRefCP(_cmRoot); 00111 subRefCP(_dsRoot); 00112 subRefCP(_ds2Root); 00113 subRefCP(_cam); 00114 subRefCP(_dsBack); 00115 subRefCP(_ds2Back); 00116 } 00117 }
|
|
||||||||||||
|
Calibrate display Definition at line 123 of file OSGDisplayCalibration.cpp. References _cmPort, _dsPort, _dsPort2, createCMViewports(), osg::DisplayCalibrationBase::getEnabled(), and osg::DisplayCalibrationBase::getScaleDown(). 00124 { 00125 if(!getEnabled()) 00126 return; 00127 00128 createCMViewports(window); 00129 00130 window->addPort(_cmPort); 00131 _cmPort->render(ract); 00132 window->subPort(_cmPort); 00133 00134 if(getScaleDown() < 1.0f) 00135 { 00136 window->addPort(_dsPort); 00137 _dsPort->render(ract); 00138 window->subPort(_dsPort); 00139 window->addPort(_dsPort2); 00140 _dsPort2->render(ract); 00141 window->subPort(_dsPort2); 00142 } 00143 00144 }
|
|
||||||||||||
|
Reimplemented from osg::AttachmentContainer. Definition at line 146 of file OSGDisplayCalibration.cpp. References _changed, and osg::AttachmentContainer::changed(). 00147 { 00148 _changed = true; 00149 Inherited::changed(whichField, origin); 00150 }
|
|
||||||||||||
|
Reimplemented from osg::AttachmentContainer. Definition at line 152 of file OSGDisplayCalibration.cpp. References SLOG. 00154 { 00155 SLOG << "Dump DisplayCalibration NI" << std::endl; 00156 }
|
|
|
Definition at line 158 of file OSGDisplayCalibration.cpp. References _argammachunk, _argammaimg, _bgammachunk, _bgammaimg, _cam, _changed, _cmBack, _cmPort, _cmRoot, _ds2Back, _ds2Root, _dsBack, _dsPort, _dsPort2, _dsRoot, _fragProgram, _gbgammachunk, _gbgammaimg, _ggammachunk, _ggammaimg, _positions, _positionsScale, _regCombiner, _rgammachunk, _rgammaimg, _texcoords, _texcoordsScale, _useFragmentProgram, _winHeight, _winWidth, osg::addRefCP(), osg::beginEditCP(), osg::MaterialChunkBase::create(), osg::SolidBackgroundBase::create(), osg::ViewportBase::create(), osg::TextureGrabBackgroundBase::create(), osg::MatrixCameraBase::create(), osg::GroupBase::create(), osg::ComponentTransformBase::create(), osg::Node::create(), osg::GeometryBase::create(), osg::GeoProperty< GeoPropertyDesc >::create(), osg::ChunkMaterialBase::create(), osg::RegisterCombinersChunkBase::create(), osg::FragmentProgramChunkBase::create(), osg::TextureChunkBase::create(), osg::ImageBase::create(), osg::endEditCP(), osg::DisplayCalibrationBase::getGammaRamp(), osg::DisplayCalibrationBase::getGrid(), osg::DisplayCalibrationBase::getGridHeight(), osg::DisplayCalibrationBase::getGridWidth(), osg::DisplayCalibrationBase::getScaleDown(), GL_CLAMP_TO_EDGE, GL_DEPENDENT_AR_TEXTURE_2D_NV, GL_DEPENDENT_GB_TEXTURE_2D_NV, GL_TEXTURE0_ARB, osg::TransformationMatrix< Real32 >::identity(), osg::makePlane(), osg::NullFC, osg::Image::OSG_L_PF, osg::osgnextpower2(), p, osg::Window::registerExtension(), osg::DisplayCalibrationBase::setScaleDown(), osg::TransformationMatrix< ValueTypeT >::setValue(), SINFO, osg::MField< FieldTypeT, fieldNameSpace >::size(), osg::subRefCP(), updateGamma(), and updateMatrix(). Referenced by calibrate(). 00159 { 00160 // create color management structures 00161 if(_cmPort != osg::NullFC && 00162 !_changed && 00163 _winWidth == window->getWidth() && 00164 _winHeight == window->getHeight()) 00165 return; 00166 00167 if(getScaleDown()>1.0) 00168 setScaleDown(1.0); 00169 00170 _changed = false; 00171 _winWidth = window->getWidth(); 00172 _winHeight = window->getHeight(); 00173 00174 // reset 00175 if(_cmPort != osg::NullFC) { 00176 subRefCP(_cmPort); 00177 subRefCP(_dsPort); 00178 subRefCP(_dsPort2); 00179 subRefCP(_cmRoot); 00180 subRefCP(_dsRoot); 00181 subRefCP(_ds2Root); 00182 subRefCP(_cam); 00183 subRefCP(_dsBack); 00184 subRefCP(_ds2Back); 00185 } 00186 00187 Matrix m; 00188 ImagePtr img = Image::create(); 00189 beginEditCP(img); 00190 img->set(GL_RGB,1,1); 00191 endEditCP(img); 00192 00193 int extension = osg::Window::registerExtension("GL_ARB_fragment_program"); 00194 if(window->hasExtension(extension)) 00195 { 00196 SINFO << "Use fragment program for color crrection" << std::endl; 00197 _useFragmentProgram = true; 00198 } 00199 else 00200 { 00201 SINFO << "Use reg combiner for color crrection" << std::endl; 00202 _useFragmentProgram = false; 00203 } 00204 00205 TextureChunkPtr tex = TextureChunk::create(); 00206 00207 if(_useFragmentProgram) 00208 { 00209 // Step 1: The texture from the GrabBackground 00210 00211 beginEditCP(tex); 00212 tex->setImage(img); 00213 tex->setMinFilter(GL_NEAREST); 00214 tex->setScale(false); 00215 tex->setEnvMode(GL_REPLACE); 00216 endEditCP (tex); 00217 00218 // Step 2: The textures for the initial gamma mapping 00219 00220 // Texture Chunks for gamma mapping 00221 00222 UChar8 rgammadata[] = 00223 { 0, 80, 160, 255 }; 00224 00225 _rgammaimg = Image::create(); 00226 beginEditCP(_rgammaimg); 00227 _rgammaimg->set(Image::OSG_L_PF,4,1,1,1,1,0,rgammadata); 00228 endEditCP(_rgammaimg); 00229 00230 _rgammachunk = TextureChunk::create(); 00231 beginEditCP(_rgammachunk); 00232 _rgammachunk->setImage(_rgammaimg); 00233 _rgammachunk->setMinFilter(GL_LINEAR); 00234 _rgammachunk->setMagFilter(GL_LINEAR); 00235 _rgammachunk->setWrapS(GL_CLAMP_TO_EDGE); 00236 _rgammachunk->setWrapT(GL_CLAMP_TO_EDGE); 00237 endEditCP (_rgammachunk); 00238 00239 UChar8 ggammadata[] = 00240 { 0, 80, 160, 255 }; 00241 00242 _ggammaimg = Image::create(); 00243 beginEditCP(_ggammaimg); 00244 _ggammaimg->set(Image::OSG_L_PF,4,1,1,1,1,0,ggammadata); 00245 endEditCP(_ggammaimg); 00246 00247 _ggammachunk = TextureChunk::create(); 00248 beginEditCP(_ggammachunk); 00249 _ggammachunk->setImage(_ggammaimg); 00250 _ggammachunk->setMinFilter(GL_LINEAR); 00251 _ggammachunk->setMagFilter(GL_LINEAR); 00252 _ggammachunk->setWrapS(GL_CLAMP_TO_EDGE); 00253 _ggammachunk->setWrapT(GL_CLAMP_TO_EDGE); 00254 endEditCP (_ggammachunk); 00255 00256 UChar8 bgammadata[] = 00257 { 0, 80, 160, 255 }; 00258 00259 _bgammaimg = Image::create(); 00260 beginEditCP(_bgammaimg); 00261 _bgammaimg->set(Image::OSG_L_PF,4,1,1,1,1,0,bgammadata); 00262 endEditCP(_bgammaimg); 00263 00264 _bgammachunk = TextureChunk::create(); 00265 beginEditCP(_bgammachunk); 00266 _bgammachunk->setImage(_bgammaimg); 00267 _bgammachunk->setMinFilter(GL_LINEAR); 00268 _bgammachunk->setMagFilter(GL_LINEAR); 00269 _bgammachunk->setWrapS(GL_CLAMP_TO_EDGE); 00270 _bgammachunk->setWrapT(GL_CLAMP_TO_EDGE); 00271 endEditCP (_bgammachunk); 00272 00273 // set gamma table 00274 for(int j=0; j < 3; ++j) 00275 { 00276 ImagePtr img; 00277 switch(j) 00278 { 00279 case 0: img = _rgammaimg; break; 00280 case 1: img = _ggammaimg; break; 00281 case 2: img = _bgammaimg; break; 00282 } 00283 beginEditCP(img); 00284 if(getGammaRamp().size() == 0) 00285 { 00286 img->set(Image::OSG_L_PF, 256, 1); 00287 UInt8 *data = img->getData(); 00288 for(int i=0; i < 256; i++) 00289 { 00290 data[i] = (UInt8)(pow(i/255.0,1.0)*255); 00291 } 00292 } 00293 else 00294 { 00295 img->set(Image::OSG_L_PF, getGammaRamp().size(), 1); 00296 UInt8 *data = img->getData(); 00297 for(int i=0; i < getGammaRamp().size(); i++) 00298 { 00299 data[i] = (UInt8)(getGammaRamp()[i][j] * 255); 00300 } 00301 } 00302 endEditCP(img); 00303 } 00304 00305 // Step 3: FragmentProgram Chunk for color matrix multiply 00306 m.setValue(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1); 00307 00308 _fragProgram = FragmentProgramChunk::create(); 00309 std::string prog( 00310 "!!ARBfp1.0\n" 00311 "PARAM mat0 = program.local[1];\n" 00312 "PARAM mat1 = program.local[2];\n" 00313 "PARAM mat2 = program.local[3];\n" 00314 "PARAM mat3 = program.local[4];\n" 00315 "PARAM gamma = program.local[5];\n" 00316 "TEMP source;\n" 00317 "TEMP target;\n" 00318 "\n" 00319 "# get the grabbed texture's color\n" 00320 "TEX source, fragment.texcoord[0], texture[0], 2D;\n" 00321 "\n" 00322 "# gamma map it\n" 00323 "POW source.r, source.r, gamma.r;\n" 00324 "POW source.g, source.g, gamma.r;\n" 00325 "POW source.b, source.b, gamma.r;\n" 00326 "\n" 00327 "# do the matrix transform\n" 00328 "DP4 target.x, mat0, source;\n" 00329 "DP4 target.y, mat1, source;\n" 00330 "DP4 target.z, mat2, source;\n" 00331 "\n" 00332 "# map it through the target gamma\n" 00333 "TEX target.r, target.r, texture[1], 1D;\n" 00334 "TEX target.g, target.g, texture[2], 1D;\n" 00335 "TEX target.b, target.b, texture[3], 1D;\n" 00336 "\n" 00337 "# mov it to the output\n" 00338 "MOV result.color, target;\n" 00339 "END\n"); 00340 00341 beginEditCP(_fragProgram); 00342 _fragProgram->setProgram(prog); 00343 endEditCP(_fragProgram); 00344 } 00345 else 00346 { 00347 // Step 1: The texture from the GrabBackground 00348 00349 beginEditCP(tex); 00350 tex->setImage(img); 00351 tex->setMinFilter(GL_NEAREST); 00352 tex->setScale(false); 00353 tex->setEnvMode(GL_REPLACE); 00354 tex->setShaderOperation(GL_TEXTURE_2D); 00355 tex->setInternalFormat(GL_RGB8); 00356 endEditCP (tex); 00357 00358 // Step 2: The textures for the initial gamma mapping 00359 00360 // Texture Chunks for gamma mapping 00361 00362 UChar8 _argammadata[] = 00363 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 00364 80, 0, 0, 80, 0, 0, 80, 0, 0, 80, 0, 0, 00365 160, 0, 0, 160, 0, 0, 160, 0, 0, 160, 0, 0, 00366 255, 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 0 00367 }; 00368 00369 _argammaimg = Image::create(); 00370 beginEditCP(_argammaimg); 00371 _argammaimg->set(GL_RGB,4,4,1,1,1,0,_argammadata); 00372 endEditCP(_argammaimg); 00373 00374 _argammachunk = TextureChunk::create(); 00375 beginEditCP(_argammachunk); 00376 _argammachunk->setImage(_argammaimg); 00377 _argammachunk->setMinFilter(GL_NEAREST); 00378 _argammachunk->setMagFilter(GL_NEAREST); 00379 _argammachunk->setWrapS(GL_CLAMP_TO_EDGE); 00380 _argammachunk->setWrapT(GL_CLAMP_TO_EDGE); 00381 _argammachunk->setShaderOperation(GL_DEPENDENT_AR_TEXTURE_2D_NV); 00382 _argammachunk->setShaderInput (GL_TEXTURE0_ARB); 00383 _argammachunk->setInternalFormat(GL_RGB8); 00384 endEditCP (_argammachunk); 00385 00386 UChar8 _gbgammadata[] = 00387 { 0, 0, 0, 0, 80, 0, 0,160, 0, 0,255, 0, 00388 0, 0, 80, 0, 80, 80, 0,160, 80, 0,255, 80, 00389 0, 0,160, 0, 80,160, 0,160,160, 0,255,160, 00390 0, 0,255, 0, 80,255, 0,160,255, 0,255,255 00391 }; 00392 00393 _gbgammaimg = Image::create(); 00394 beginEditCP(_gbgammaimg); 00395 _gbgammaimg->set(GL_RGB,4,4,1,1,1,0,_gbgammadata); 00396 endEditCP(_gbgammaimg); 00397 00398 _gbgammachunk = TextureChunk::create(); 00399 beginEditCP(_gbgammachunk); 00400 _gbgammachunk->setImage(_gbgammaimg); 00401 _gbgammachunk->setMinFilter(GL_NEAREST); 00402 _gbgammachunk->setMagFilter(GL_NEAREST); 00403 _gbgammachunk->setWrapS(GL_CLAMP_TO_EDGE); 00404 _gbgammachunk->setWrapT(GL_CLAMP_TO_EDGE); 00405 _gbgammachunk->setShaderOperation(GL_DEPENDENT_GB_TEXTURE_2D_NV); 00406 _gbgammachunk->setShaderInput (GL_TEXTURE0_ARB); 00407 _gbgammachunk->setInternalFormat(GL_RGB8); 00408 endEditCP (_gbgammachunk); 00409 00410 // Step 3: RegisterCombiners Chunk for color matrix multiply 00411 00412 m.setValue(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1); 00413 m.setValue(1,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,1); 00414 00415 _regCombiner = RegisterCombinersChunk::create(); 00416 } 00417 00418 // putting it all together 00419 00420 ChunkMaterialPtr mat = ChunkMaterial::create(); 00421 beginEditCP(mat); 00422 mat->addChunk(tex); 00423 if(_useFragmentProgram) 00424 { 00425 mat->addChunk(_rgammachunk); 00426 mat->addChunk(_ggammachunk); 00427 mat->addChunk(_bgammachunk); 00428 mat->addChunk(_fragProgram); 00429 } 00430 else 00431 { 00432 mat->addChunk(_argammachunk); 00433 mat->addChunk(_gbgammachunk); 00434 mat->addChunk(_regCombiner); 00435 } 00436 endEditCP(mat); 00437 00438 // add the second viewport 00439 00440 GeoPTypesUI8Ptr types = GeoPTypesUI8::create(); 00441 GeoPLengthsPtr lens = GeoPLengthsUI32::create(); 00442 beginEditCP(types); 00443 types->addValue(GL_QUADS); 00444 endEditCP(types); 00445 00446 beginEditCP(lens); 00447 lens->addValue(4); 00448 endEditCP(lens); 00449 00450 GeoPositions3fPtr pos = GeoPositions3f::create(); 00451 beginEditCP(pos); 00452 pos->addValue(Pnt3f(-1, -1, -0.5)); 00453 pos->addValue(Pnt3f( 1, -1, -0.5)); 00454 pos->addValue(Pnt3f( 1, 1, -0.5)); 00455 pos->addValue(Pnt3f(-1, 1, -0.5)); 00456 endEditCP(pos); 00457 _positions=pos; 00458 00459 _texcoords = GeoTexCoords2f::create(); 00460 beginEditCP(_texcoords); 00461 _texcoords->addValue(Vec2f(0,0)); 00462 _texcoords->addValue(Vec2f(1,0)); 00463 _texcoords->addValue(Vec2f(1,1)); 00464 _texcoords->addValue(Vec2f(0,1)); 00465 endEditCP(_texcoords); 00466 00467 GeometryPtr geo = Geometry::create(); 00468 beginEditCP(geo); 00469 geo->setMaterial(mat); 00470 geo->setPositions(pos); 00471 geo->setTypes(types); 00472 geo->setTexCoords(_texcoords); 00473 geo->setLengths(lens); 00474 endEditCP (geo); 00475 00476 NodePtr cube = Node::create(); 00477 beginEditCP(cube); 00478 cube->setCore(geo); 00479 endEditCP(cube); |