Changeset 1958
- Timestamp:
- 01/08/07 18:40:01 (18 years ago)
- Location:
- GTP/trunk/Lib/Vis/Preprocessing/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.cpp
r1954 r1958 106 106 { 107 107 //globalLinesRenderer->DrawGeometry(); 108 globalLinesRenderer->CastGlobalLines(Beam(), 0); 108 //globalLinesRenderer->CastGlobalLines(Beam(), 0); 109 globalLinesRenderer->DisplayBuffer(); 109 110 PrintGLerror("display"); 110 111 … … 124 125 { 125 126 case '2': 126 ++ globalLinesRenderer->mMaxDepth; 127 cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl; 128 return; 127 { 128 VssRayContainer rays; 129 130 ++ globalLinesRenderer->mMaxDepth; 131 globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0); 132 133 cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl; 134 return; 135 } 129 136 case '1': 130 -- globalLinesRenderer->mMaxDepth; 131 cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl; 132 return; 137 { 138 VssRayContainer rays; 139 140 -- globalLinesRenderer->mMaxDepth; 141 cout << "max depth: " << globalLinesRenderer->mMaxDepth << endl; 142 143 globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0); 144 return; 145 } 133 146 case '3': 134 //globalLinesRenderer->ApplyDepthPeeling(Beam(), 0); 135 globalLinesRenderer->GrabDepthBuffer(globalLinesRenderer->mNewDepthBuffer, globalLinesRenderer->mNewTexture); 147 { 148 //globalLinesRenderer->ApplyDepthPeeling(Beam(), 0); 149 globalLinesRenderer->ExportDepthBuffer(); 150 return; 151 } 152 case '4': 153 { 154 VssRayContainer rays; 155 156 globalLinesRenderer->ApplyDepthPeeling(rays, Beam(), 0); 157 return; 158 } 136 159 default: 137 160 return; … … 162 185 163 186 187 void GlobalLinesRenderer::DisplayBuffer() 188 { 189 //mNewTexture->Bind(); 190 mNewTexture->BindDepth(); 191 mNewTexture->EnableTextureTarget(); 192 193 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 194 195 if (mNewTexture->IsRectangleTexture()) 196 { 197 glBegin(GL_QUADS); 198 glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 199 glTexCoord2f(mNewTexture->GetWidth(), 0); glVertex3f( 1, -1, -0.5f); 200 glTexCoord2f(mNewTexture->GetWidth(), mNewTexture->GetHeight()); glVertex3f( 1, 1, -0.5f); 201 glTexCoord2f(0, mNewTexture->GetHeight()); glVertex3f(-1, 1, -0.5f); 202 glEnd(); 203 } 204 else 205 { 206 glBegin(GL_QUADS); 207 glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 208 glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f); 209 glTexCoord2f(1, 1); glVertex3f( 1, 1, -0.5f); 210 glTexCoord2f(0, 1); glVertex3f(-1, 1, -0.5f); 211 glEnd(); 212 } 213 214 mNewTexture->DisableTextureTarget(); 215 PrintGLerror("displaytexture"); 216 } 217 218 164 219 GlobalLinesRenderer::~GlobalLinesRenderer() 165 220 { … … 168 223 if (sCgContext) 169 224 cgDestroyContext(sCgContext); 225 226 // init the receiving buffers 227 delete mNewDepthBuffer; 228 delete mOldDepthBuffer; 229 230 delete mNewItemBuffer; 231 delete mOldItemBuffer; 170 232 } 171 233 … … 173 235 void GlobalLinesRenderer::CastGlobalLines(Beam &beam, const int samples) 174 236 { 237 VssRayContainer rays; 238 175 239 // bind pixel shader implementing the front depth buffer functionality 176 ApplyDepthPeeling( beam, samples);240 ApplyDepthPeeling(rays, beam, samples); 177 241 } 178 242 … … 192 256 { 193 257 //glLoadIdentity(); 194 195 //mRenderer->mUseFalseColors = true;196 258 ObjectContainer::const_iterator oit, oit_end = mPreprocessor->mObjects.end(); 197 259 … … 215 277 216 278 279 void GlobalLinesRenderer::ComputeLookAt(const float alpha, 280 const float beta, 281 Vector3 &eye, 282 Vector3 &up, 283 Vector3 left) 284 { 285 //float x = cos(alpha); 286 //float y = sin(alpha); 287 eye.x = sin(alpha) * cos(beta); 288 eye.y = sin(alpha) * sin(beta); 289 eye.z = cos(beta); 290 291 eye.RightHandedBase(up, left); 292 } 293 294 217 295 void GlobalLinesRenderer::InitGl() 218 296 { … … 241 319 glLoadIdentity(); 242 320 243 // init the receiving buffers321 // initialise the receiving buffers 244 322 mNewDepthBuffer = new float[texWidth * texHeight]; 245 323 mOldDepthBuffer = new float[texWidth * texHeight]; 246 324 325 for (int i = 0; i < texWidth * texHeight; ++ i) 326 { 327 mNewDepthBuffer[i] = 1; 328 mOldDepthBuffer[i] = 1; 329 } 330 247 331 mNewItemBuffer = new int[texWidth * texHeight *4]; 248 332 mOldItemBuffer = new int[texWidth * texHeight *4]; 249 333 334 for (int i = 0; i < texWidth * texHeight * 4; ++ i) 335 { 336 mNewItemBuffer[i] = 0; 337 mOldItemBuffer[i] = 0; 338 } 339 250 340 AxisAlignedBox3 bbox = globalLinesRenderer->mPreprocessor->mKdTree->GetBox(); 251 341 252 Vector3 midPoint = bbox.Center();342 mViewPoint = bbox.Center(); 253 343 254 344 const float sceneSize = Magnitude(bbox.Diagonal()); 255 Vector3 viewPoint = m idPoint + Vector3(0.5 * sceneSize, 0, 0);256 257 cout << "mid point: " << m idPoint << endl;345 Vector3 viewPoint = mViewPoint + Vector3(0.5 * sceneSize, 0, 0); 346 347 cout << "mid point: " << mViewPoint << endl; 258 348 cout << "view point: " << viewPoint << endl; 259 349 cout << "scene: " << bbox << endl; 350 351 mEyeVec = Normalize(viewPoint - mViewPoint); 352 mEyeVec.RightHandedBase(mUpVec, mLeftVec); 260 353 261 354 /*gluLookAt(viewPoint.x, viewPoint.y, viewPoint.z, … … 331 424 SetFrustum(sceneSize, sceneSize, 1, sceneSize); 332 425 333 glClearColor(0.1, 0.7, 0.2, 1); 426 // for item buffer: white means no color 427 glClearColor(1, 1, 1, 1); 334 428 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 335 429 … … 343 437 glLoadIdentity(); 344 438 gluLookAt(viewPoint.x, viewPoint.y, viewPoint.z, 345 m idPoint.x, midPoint.y, midPoint.z,439 mViewPoint.x, mViewPoint.y, mViewPoint.z, 346 440 0, 1, 0); 347 441 … … 350 444 mNewTexture->EndCapture(); 351 445 352 // setup the rendering context for the RenderTexture446 // setup the rendering context for the other depth buffer 353 447 mOldTexture->BeginCapture(); 354 448 { 355 glClearColor(0.1, 0.7, 0.2, 1); 449 // for item buffer: white means no color 450 glClearColor(1, 1, 1, 1); 356 451 357 452 //Reshape(texWidth, texHeight); … … 369 464 370 465 gluLookAt(viewPoint.x, viewPoint.y, viewPoint.z, 371 m idPoint.x, midPoint.y, midPoint.z,466 mViewPoint.x, mViewPoint.y, mViewPoint.z, 372 467 0, 1, 0); 373 468 … … 406 501 407 502 float newDummy2 = x - texWidth / 2; 408 float newDummy3 = y - 503 float newDummy3 = y - texHeight / 2; 409 504 410 505 float oldDummy2 = newDummy2; 411 506 float oldDummy3 = newDummy3; 412 507 413 const Vector3 newPt = newDepth * mEyeVec + newDummy1 * mLeftVec + newDummy2 * mUpVec; 414 const Vector3 oldPt = oldDepth * mEyeVec + oldDummy1 * mLeftVec + oldDummy2 * mUpVec; 415 416 Intersectable *termObj1 = GetObject(mNewItemBuffer[index]); 417 Intersectable *termObj2 = GetObject(mOldItemBuffer[index]); 418 508 const Vector3 newPt = mViewPoint + newDepth * mEyeVec + newDummy1 * mLeftVec + newDummy2 * mUpVec; 509 const Vector3 oldPt = mViewPoint + oldDepth * mEyeVec + oldDummy1 * mLeftVec + oldDummy2 * mUpVec; 510 511 //cout << "viewpoint: " << mViewPoint << " new: " << newPt << " old: " << newPt << endl; 512 513 int r = mNewItemBuffer[index]; 514 int g = mNewItemBuffer[index + 1]; 515 int b = mNewItemBuffer[index + 2]; 516 517 Intersectable *termObj1 = NULL; 518 Intersectable *termObj2 = NULL; 519 520 // 3 times 255 means no valid object 521 if (!((r == 255) && (g == 255) && (b == 255))) 522 { 523 const int id = mRenderer->GetId(r, g, b); 524 cout << id << " "; 525 //termObj1 = mPreprocessor->GetObjectById(id); 526 } 527 528 /*r = mOldItemBuffer[index]; 529 g = mOldItemBuffer[index + 1]; 530 b = mOldItemBuffer[index + 2]; 531 532 if (!((r == 255) && (g == 255) && (b == 255))) 533 Intersectable *termObj2 = mPreprocessor->GetObjectById(mRenderer->GetId(r, g, b)); 534 */ 419 535 // create rays in both directions 420 vssRays.push_back(new VssRay(oldPt, newPt, NULL, termObj1));421 vssRays.push_back(new VssRay(newPt, oldPt, NULL, termObj2));536 //vssRays.push_back(new VssRay(oldPt, newPt, NULL, termObj1)); 537 //vssRays.push_back(new VssRay(newPt, oldPt, NULL, termObj2)); 422 538 } 423 539 } … … 446 562 void GlobalLinesRenderer::GrabItemBuffer(int *data, RenderTexture *rt) 447 563 { 448 rt->Bind Depth();564 rt->Bind(); 449 565 rt->EnableTextureTarget(); 450 cout << "depth: " << mNewTexture->GetDepthBits() << endl;451 452 const int texFormat = GL_ DEPTH_COMPONENT;566 //cout << "depth: " << mNewTexture->GetDepthBits() << endl; 567 568 const int texFormat = GL_RGBA; 453 569 glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_FLOAT, data); 454 570 455 571 mNewTexture->DisableTextureTarget(); 456 572 } 573 457 574 458 575 void GlobalLinesRenderer::ExportDepthBuffer() … … 493 610 494 611 495 void GlobalLinesRenderer::ApplyDepthPeeling(Beam &beam, const int samples) 612 /* 613 void GlobalLinesRenderer::ExportItemBuffer() 614 { 615 mNewTexture->BindDepth(); 616 mNewTexture->EnableTextureTarget(); 617 cout << "depth: " << mNewTexture->GetDepthBits() << endl; 618 619 const bool components = 1;//mNewTexture->GetDepthBits() / 8; 620 621 float *data = new float[texWidth * texHeight * components]; 622 //const int texFormat = WGL_TEXTURE_DEPTH_COMPONENT_NV; 623 const int texFormat = GL_DEPTH_COMPONENT; 624 //const int texFormat = GL_RGBA; 625 glGetTexImage(mNewTexture->GetTextureTarget(), 0, texFormat, GL_FLOAT, data); 626 627 string filename("depth.tga"); 628 ilRegisterType(IL_FLOAT); 629 630 const int depth = 1; 631 const int bpp = components; 632 633 ilTexImage(texWidth, texHeight, depth, bpp, IL_LUMINANCE, IL_FLOAT, data); 634 ilSaveImage((char *const)filename.c_str()); 635 636 cout << "finished" << endl; 637 delete data; 638 cout << "data deleted" << endl; 639 mNewTexture->DisableTextureTarget(); 640 PrintGLerror("grab texture"); 641 } 642 */ 643 644 645 void GlobalLinesRenderer::ApplyDepthPeeling(VssRayContainer &rays, 646 Beam &beam, 647 const int samples) 496 648 { 497 649 mNewTexture->BeginCapture(); … … 504 656 505 657 PrintGLerror("firstpass"); 506 507 658 if (mNewTexture->IsRectangleTexture()) cout << "rect" << endl; 659 660 // process the buffers for the first layer 661 ProcessDepthBuffer(rays); 508 662 509 663 for(int i = 0; i < mMaxDepth; ++ i) … … 520 674 521 675 cgGLBindProgram(sCgDepthPeelingProgram); 522 // cgGLBindProgram(sCgPassThroughProgram);523 676 cgGLEnableProfile(sCgFragmentProfile); 524 677 cgGLSetTextureParameter(sTextureParam, mOldTexture->GetDepthTextureID()); … … 532 685 cgGLDisableTextureParameter(sTextureParam); 533 686 cgGLDisableProfile(sCgFragmentProfile); 687 688 // process the buffers for following layer 689 ProcessDepthBuffer(rays); 690 534 691 } 535 692 mNewTexture->EndCapture(); … … 537 694 538 695 PrintGLerror("endpeeling"); 539 540 //mNewTexture->Bind(); 541 mNewTexture->BindDepth(); 542 mNewTexture->EnableTextureTarget(); 543 544 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 545 546 if (mNewTexture->IsRectangleTexture()) 547 { 548 glBegin(GL_QUADS); 549 glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 550 glTexCoord2f(mNewTexture->GetWidth(), 0); glVertex3f( 1, -1, -0.5f); 551 glTexCoord2f(mNewTexture->GetWidth(), mNewTexture->GetHeight()); glVertex3f( 1, 1, -0.5f); 552 glTexCoord2f(0, mNewTexture->GetHeight()); glVertex3f(-1, 1, -0.5f); 553 glEnd(); 554 } 555 else 556 { 557 glBegin(GL_QUADS); 558 glTexCoord2f(0, 0); glVertex3f(-1, -1, -0.5f); 559 glTexCoord2f(1, 0); glVertex3f( 1, -1, -0.5f); 560 glTexCoord2f(1, 1); glVertex3f( 1, 1, -0.5f); 561 glTexCoord2f(0, 1); glVertex3f(-1, 1, -0.5f); 562 glEnd(); 563 } 564 565 mNewTexture->DisableTextureTarget(); 566 PrintGLerror("displaytexture"); 567 } 568 569 570 } 696 } 697 698 699 } -
GTP/trunk/Lib/Vis/Preprocessing/src/GlobalLinesRenderer.h
r1954 r1958 51 51 void GrabDepthBuffer(float *data, RenderTexture *rt); 52 52 void GrabItemBuffer(int *data, RenderTexture *rt); 53 void ApplyDepthPeeling( Beam &beam, const int samples);53 void ApplyDepthPeeling(VssRayContainer &rays, Beam &beam, const int samples); 54 54 void ExportDepthBuffer(); 55 55 void ProcessDepthBuffer(VssRayContainer &vssRays); 56 void DisplayBuffer(); 56 57 57 58 int mMaxDepth; … … 62 63 float mNear; 63 64 65 Vector3 mViewPoint; 66 64 67 float *mNewDepthBuffer; 65 68 float *mOldDepthBuffer; … … 68 71 RenderTexture *mNewTexture; 69 72 RenderTexture *mOldTexture; 73 74 void ComputeLookAt(const float alpha, 75 const float beta, 76 Vector3 &eye, 77 Vector3 &up, 78 Vector3 left); 70 79 protected: 71 72 void ProcessDepthBuffer();73 80 74 81 void SwitchRenderTextures(); -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.cpp
r1940 r1958 1294 1294 } 1295 1295 1296 } 1296 1297 Intersectable *Preprocessor::GetObjectById(const int id) 1298 { 1299 #if 0 1300 // create a dummy mesh instance to be able to use stl 1301 MeshInstance object(NULL); 1302 object.SetId(id); 1303 1304 ObjectContainer::const_iterator oit = 1305 lower_bound(mObjects.begin(), mObjects.end(), &object, ilt); 1306 1307 // objects sorted by id 1308 if ((oit != mObjects.end()) && ((*oit)->GetId() == object.GetId())) 1309 { 1310 return (*oit); 1311 } 1312 else 1313 { 1314 return NULL; 1315 } 1316 #else 1317 return mObjects[id]; 1318 #endif 1319 } 1320 1321 } -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.h
r1942 r1958 147 147 const bool pruneInvalidRays = true); 148 148 149 /** Compute pixel error of the current PVS solution by sampling given number of viewpoints */ 150 virtual void 151 ComputeRenderError(); 149 /** Compute pixel error of the current PVS solution by sampling given number of viewpoints */ 150 virtual void ComputeRenderError(); 152 151 153 152 /** Returns a view cells manager of the given name. … … 172 171 PreprocessorThread *GetThread() const; 173 172 173 174 Intersectable *GetObjectById(const int id); 174 175 175 176 -
GTP/trunk/Lib/Vis/Preprocessing/src/Preprocessor.vcproj
r1949 r1958 717 717 </File> 718 718 <File 719 RelativePath=".\QtPreprocessorThread.cpp">720 </File>721 <File722 RelativePath=".\QtPreprocessorThread.h">723 </File>724 <File725 719 RelativePath="..\src\Ray.cpp"> 726 720 </File> -
GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.cpp
r1344 r1958 181 181 } 182 182 183 183 184 } -
GTP/trunk/Lib/Vis/Preprocessing/src/SceneGraph.h
r1328 r1958 53 53 void SetRoot(SceneGraphNode *sgNnode); 54 54 55 55 56 protected: 56 57 -
GTP/trunk/Lib/Vis/Preprocessing/src/Vector3.h
r1883 r1958 184 184 // Viewer is the coordinates of viewer location, UpL is the vector. 185 185 friend void ViewVectors(const Vector3 &DirAt, const Vector3 &Viewer, 186 187 Vector3 &ViewU, Vector3 &ViewN );186 const Vector3 &UpL, Vector3 &ViewV, 187 Vector3 &ViewU, Vector3 &ViewN ); 188 188 189 189 // Given the intersection point `P', you have available normal `N' … … 262 262 263 263 264 inline void 265 Vector3::RightHandedBase(Vector3& U, Vector3& V) const 266 { 267 // HACK 268 V = ArbitraryNormal(*this); 269 U = CrossProd(V, *this); 270 } 271 272 264 273 inline Vector3 265 274 ToGlobalFrame(const Vector3 &loc,
Note: See TracChangeset
for help on using the changeset viewer.