]> OCCT Git - occt.git/commitdiff
0028758: Visualization - Implement exporting generated image to HRD/EXR images
authorage <age@opencascade.com>
Tue, 16 May 2017 10:37:50 +0000 (13:37 +0300)
committerbugmaster <bugmaster@opencascade.com>
Thu, 25 May 2017 08:46:47 +0000 (11:46 +0300)
OpenGl_View::BufferDump() - added support for dumping RayTracing HDR buffers.
Added new buffer type Graphic3d_BT_RGB_RayTraceHdrLeft.

src/Graphic3d/Graphic3d_BufferType.hxx
src/Image/Image_AlienPixMap.cxx
src/OpenGl/OpenGl_View.cxx
src/OpenGl/OpenGl_View.hxx
src/V3d/V3d_View.cxx
src/ViewerTest/ViewerTest.cxx

index e09cb1e5324a3a60e34a33281a1b59dae0d6d026..d4e7c5b6f47e31b9a2bfd18d12ca5bb0369af69e 100644 (file)
@@ -19,7 +19,8 @@ typedef enum
 {
   Graphic3d_BT_RGB,   //!< color buffer without alpha component
   Graphic3d_BT_RGBA,  //!< color buffer
-  Graphic3d_BT_Depth  //!< depth buffer
+  Graphic3d_BT_Depth,  //!< depth buffer
+  Graphic3d_BT_RGB_RayTraceHdrLeft //!< left view HDR color buffer for Ray-Tracing
 } Graphic3d_BufferType;
 
 #endif // _Graphic3d_BufferType_H__
index f7d132761e7eb2d99950680e235b62e10dc90931..34d5723eb5fcb4516b904d75c59de752db4f8e2d 100644 (file)
@@ -461,6 +461,7 @@ bool Image_AlienPixMap::Save (const TCollection_AsciiString& theFileName)
       }
       break;
     }
+    case FIF_HDR:
     case FIF_EXR:
     {
       if (Format() == Image_Format_Gray
index e669a9c6b25ce16392dc6c0e9149afe134521fd7..fd181f838ee047636788f309b3bc8f6781ba9f54 100644 (file)
@@ -353,7 +353,58 @@ void OpenGl_View::GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, c
 // =======================================================================
 Standard_Boolean OpenGl_View::BufferDump (Image_PixMap& theImage, const Graphic3d_BufferType& theBufferType)
 {
-  return myWorkspace->BufferDump (myFBO, theImage, theBufferType);
+  if (theBufferType != Graphic3d_BT_RGB_RayTraceHdrLeft)
+  {
+    return myWorkspace->BufferDump(myFBO, theImage, theBufferType);
+  }
+
+  if (!myRaytraceParameters.AdaptiveScreenSampling)
+  {
+    return myWorkspace->BufferDump(myAccumFrames % 2 ? myRaytraceFBO2[0] : myRaytraceFBO1[0], theImage, theBufferType);
+  }
+
+#if defined(GL_ES_VERSION_2_0)
+  return false;
+#else
+  if (theImage.Format() != Image_Format_RGBF)
+  {
+    return false;
+  }
+
+  const GLuint aW = myRaytraceOutputTexture[0]->SizeX();
+  const GLuint aH = myRaytraceOutputTexture[0]->SizeY();
+  if (aW / 3 != theImage.SizeX() || aH / 2 != theImage.SizeY())
+  {
+    return false;
+  }
+
+  std::vector<GLfloat> aValues;
+  try
+  {
+    aValues.resize (aW * aH);
+  }
+  catch (const std::bad_alloc&)
+  {
+    return false;
+  }
+
+  glBindTexture (GL_TEXTURE_RECTANGLE, myRaytraceOutputTexture[0]->TextureId());
+  glGetTexImage (GL_TEXTURE_RECTANGLE, 0, OpenGl_TextureFormat::Create<GLfloat, 1>().Format(), GL_FLOAT, &aValues[0]);
+  glBindTexture (GL_TEXTURE_RECTANGLE, 0);
+  for (unsigned int aRow = 0; aRow < aH; aRow += 2)
+  {
+    for (unsigned int aCol = 0; aCol < aW; aCol += 3)
+    {
+      float* anImageValue = theImage.ChangeValue<float[3]> ((aH - aRow) / 2 - 1, aCol / 3);
+      float aInvNbSamples = 1.f / aValues[aRow * aW + aCol + aW];
+      anImageValue[0] = aValues[aRow * aW + aCol] * aInvNbSamples;
+      anImageValue[1] = aValues[aRow * aW + aCol + 1] * aInvNbSamples;
+      anImageValue[2] = aValues[aRow * aW + aCol + 1 + aW] * aInvNbSamples;
+    }
+  }
+
+  return true;
+#endif
 }
 
 // =======================================================================
index 8ed3c5dc2b0efafb67e57c622aaa1dd58eb46f5d..cfe2e552d7392b2242d233230fe90e316e035dfb 100644 (file)
@@ -143,6 +143,8 @@ public:
   Standard_EXPORT virtual void GraduatedTrihedronMinMaxValues (const Graphic3d_Vec3 theMin, const Graphic3d_Vec3 theMax) Standard_OVERRIDE;
 
   //! Dump active rendering buffer into specified memory buffer.
+  //! In Ray-Tracing allow to get a raw HDR buffer using Graphic3d_BT_RGB_RayTraceHdrLeft buffer type,
+  //! only Left view will be dumped ignoring stereoscopic parameter.
   Standard_EXPORT virtual Standard_Boolean BufferDump (Image_PixMap& theImage,
                                                        const Graphic3d_BufferType& theBufferType) Standard_OVERRIDE;
 
index df7ef19a4b164886c69fb12710472f953420b348..00413cd4bd933b5f02598b295035eadf7d873ed8 100644 (file)
@@ -2831,9 +2831,10 @@ Standard_Boolean V3d_View::ToPixMap (Image_PixMap&               theImage,
       Image_Format aFormat = Image_Format_UNKNOWN;
       switch (theParams.BufferType)
       {
-        case Graphic3d_BT_RGB:   aFormat = Image_Format_RGB;   break;
-        case Graphic3d_BT_RGBA:  aFormat = Image_Format_RGBA;  break;
-        case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
+        case Graphic3d_BT_RGB:                 aFormat = Image_Format_RGB;   break;
+        case Graphic3d_BT_RGBA:                aFormat = Image_Format_RGBA;  break;
+        case Graphic3d_BT_Depth:               aFormat = Image_Format_GrayF; break;
+        case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF;  break;
       }
 
       if (!theImage.InitZero (aFormat, Standard_Size(aTargetSize.x()), Standard_Size(aTargetSize.y())))
index 2896cdd89a0feb54891eae89a3fc9d62b90e659d..33a6078cff2f73f44c01d1d8386abe6291ef02be 100644 (file)
@@ -1076,9 +1076,10 @@ static Standard_Integer VDump (Draw_Interpretor& theDI,
   Image_Format aFormat = Image_Format_UNKNOWN;
   switch (aParams.BufferType)
   {
-    case Graphic3d_BT_RGB:   aFormat = Image_Format_RGB;   break;
-    case Graphic3d_BT_RGBA:  aFormat = Image_Format_RGBA;  break;
-    case Graphic3d_BT_Depth: aFormat = Image_Format_GrayF; break;
+    case Graphic3d_BT_RGB:                 aFormat = Image_Format_RGB;   break;
+    case Graphic3d_BT_RGBA:                aFormat = Image_Format_RGBA;  break;
+    case Graphic3d_BT_Depth:               aFormat = Image_Format_GrayF; break;
+    case Graphic3d_BT_RGB_RayTraceHdrLeft: aFormat = Image_Format_RGBF;  break;
   }
 
   switch (aStereoPair)