0024548: Ray Tracing mode not available in MFC samples
authorski <ski@opencascade.com>
Thu, 30 Oct 2014 13:03:24 +0000 (16:03 +0300)
committerbugmaster <bugmaster@opencascade.com>
Wed, 5 Nov 2014 14:17:47 +0000 (17:17 +0300)
Ray tracing functionality was added to OCCT MFC samples.

15 files changed:
samples/mfc/standard/Common/OCC_3dBaseDoc.cpp
samples/mfc/standard/Common/OCC_3dBaseDoc.h
samples/mfc/standard/Common/OCC_3dChildFrame.cpp
samples/mfc/standard/Common/OCC_3dChildFrame.h
samples/mfc/standard/Common/res/OCC_Resource.h
samples/mfc/standard/Common/res/OCC_Resource.rc
samples/mfc/standard/Common/res/ToolbarRayTracing.bmp [new file with mode: 0644]
samples/mfc/standard/mfcsample/adm/win/vc10/mfcsample.vcxproj
samples/mfc/standard/mfcsample/adm/win/vc10/mfcsample.vcxproj.filters
samples/mfc/standard/mfcsample/adm/win/vc11/mfcsample.vcxproj
samples/mfc/standard/mfcsample/adm/win/vc11/mfcsample.vcxproj.filters
samples/mfc/standard/mfcsample/adm/win/vc12/mfcsample.vcxproj
samples/mfc/standard/mfcsample/adm/win/vc12/mfcsample.vcxproj.filters
samples/mfc/standard/mfcsample/adm/win/vc8/mfcsample.vcproj
samples/mfc/standard/mfcsample/adm/win/vc9/mfcsample.vcproj

index 407ac62..6e225fd 100755 (executable)
@@ -42,6 +42,17 @@ BEGIN_MESSAGE_MAP(OCC_3dBaseDoc, OCC_BaseDoc)
   //}}AFX_MSG_MAP
   ON_COMMAND_EX_RANGE(ID_OBJECT_MATERIAL_BRASS,ID_OBJECT_MATERIAL_DEFAULT, OnObjectMaterialRange)
   ON_UPDATE_COMMAND_UI_RANGE(ID_OBJECT_MATERIAL_BRASS,ID_OBJECT_MATERIAL_DEFAULT, OnUpdateObjectMaterialRange)
+
+  //RayTracing
+  ON_COMMAND(ID_OBJECT_RAY_TRACING,OnObjectRayTracing)
+  ON_COMMAND(ID_OBJECT_SHADOWS,OnObjectShadows)
+  ON_COMMAND(ID_OBJECT_REFLECTIONS,OnObjectReflections)
+  ON_COMMAND(ID_OBJECT_ANTI_ALIASING,OnObjectAntiAliasing)
+
+  ON_UPDATE_COMMAND_UI(ID_OBJECT_RAY_TRACING, OnUpdateV3dButtons)
+  ON_UPDATE_COMMAND_UI(ID_OBJECT_SHADOWS, OnUpdateV3dButtons)
+  ON_UPDATE_COMMAND_UI(ID_OBJECT_REFLECTIONS, OnUpdateV3dButtons)
+  ON_UPDATE_COMMAND_UI(ID_OBJECT_ANTI_ALIASING, OnUpdateV3dButtons)
 END_MESSAGE_MAP()
 
 
@@ -60,6 +71,11 @@ OCC_3dBaseDoc::OCC_3dBaseDoc()
   myViewer->SetDefaultLights();
   myViewer->SetLightOn();
   myAISContext = new AIS_InteractiveContext (myViewer);
+
+  myRayTracingIsOn            = false;
+  myRaytracedShadowsIsOn      = true;
+  myRaytracedReflectionsIsOn  = false;
+  myRaytracedAntialiasingIsOn = false;
 }
 
 OCC_3dBaseDoc::~OCC_3dBaseDoc()
@@ -424,3 +440,65 @@ void OCC_3dBaseDoc::SetMaterial(Graphic3d_NameOfMaterial Material)
     myAISContext->SetMaterial (myAISContext->Current(),
     (Graphic3d_NameOfMaterial)(Material));
 }
+
+
+// RayTracing
+void OCC_3dBaseDoc::OnObjectRayTracing()
+{
+  myRayTracingIsOn = !myRayTracingIsOn;
+  if(!myRayTracingIsOn)
+  {
+    myRaytracedShadowsIsOn = false;
+    myRaytracedReflectionsIsOn = false;
+    myRaytracedAntialiasingIsOn = false;
+  }
+  OnObjectRayTracingAction();
+}
+// Shadows
+void OCC_3dBaseDoc::OnObjectShadows()
+{
+  myRaytracedShadowsIsOn = !myRaytracedShadowsIsOn;
+  OnObjectRayTracingAction();
+}
+// Reflections
+void OCC_3dBaseDoc::OnObjectReflections()
+{
+  myRaytracedReflectionsIsOn = !myRaytracedReflectionsIsOn;
+  OnObjectRayTracingAction();
+}
+// Anti-aliasing
+void OCC_3dBaseDoc::OnObjectAntiAliasing()
+{
+  myRaytracedAntialiasingIsOn = !myRaytracedAntialiasingIsOn;
+  OnObjectRayTracingAction();
+}
+void OCC_3dBaseDoc::OnUpdateV3dButtons (CCmdUI* pCmdUI)
+{
+  if (pCmdUI->m_nID == ID_OBJECT_RAY_TRACING)
+  {
+    pCmdUI->SetCheck(myRayTracingIsOn);
+  } else {
+    pCmdUI->Enable(myRayTracingIsOn);
+    if (pCmdUI->m_nID == ID_OBJECT_SHADOWS)
+      pCmdUI->SetCheck(myRaytracedShadowsIsOn);
+    if (pCmdUI->m_nID == ID_OBJECT_REFLECTIONS)
+      pCmdUI->SetCheck(myRaytracedReflectionsIsOn);
+    if (pCmdUI->m_nID == ID_OBJECT_ANTI_ALIASING)
+      pCmdUI->SetCheck(myRaytracedAntialiasingIsOn);
+  }
+}
+// Common function to change raytracing params and redraw view
+void OCC_3dBaseDoc::OnObjectRayTracingAction()
+{
+  myAISContext->CurrentViewer()->InitActiveViews();
+  Handle(V3d_View) aView = myAISContext->CurrentViewer()->ActiveView();
+  Graphic3d_RenderingParams& aParams = aView->ChangeRenderingParams();
+  if (myRayTracingIsOn)
+    aParams.Method = Graphic3d_RM_RAYTRACING;
+  else
+    aParams.Method = Graphic3d_RM_RASTERIZATION;
+  aParams.IsShadowEnabled = myRaytracedShadowsIsOn;
+  aParams.IsReflectionEnabled = myRaytracedReflectionsIsOn;
+  aParams.IsAntialiasingEnabled = myRaytracedAntialiasingIsOn;
+  myAISContext->UpdateCurrentViewer();
+}
index e590141..eff5954 100755 (executable)
@@ -57,6 +57,8 @@ public:
 
   int  OnFileImportBrep_WithInitDir (const wchar_t* InitialDir);
 
+  void OnObjectRayTracingAction();
+
   // Generated message map functions
 protected:
   //{{AFX_MSG(OCC_3dBaseDoc)
@@ -81,11 +83,20 @@ protected:
   afx_msg void OnObjectRemove();
   afx_msg void OnUpdateObjectRemove(CCmdUI* pCmdUI);
 
+  afx_msg void OnUpdateV3dButtons(CCmdUI* pCmdUI);
+  afx_msg void OnObjectRayTracing();
+  afx_msg void OnObjectShadows();
+  afx_msg void OnObjectReflections();
+  afx_msg void OnObjectAntiAliasing();
+
   //}}AFX_MSG
   DECLARE_MESSAGE_MAP()
 
 protected:
-
+  bool myRayTracingIsOn;
+  bool myRaytracedShadowsIsOn;
+  bool myRaytracedReflectionsIsOn;
+  bool myRaytracedAntialiasingIsOn;
   int myPopupMenuNumber;
 };
 
index 77f6a8a..c4d3409 100755 (executable)
@@ -47,5 +47,17 @@ int OCC_3dChildFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
   EnableDocking(CBRS_ALIGN_ANY);
   DockControlBar(&m_wndToolBar);
 
+  // Create toolbar for RayTracing functionality
+  if (!m_RTToolBar.Create(this) || !m_RTToolBar.LoadToolBar(IDR_RAY_TRACING))
+  {
+    TRACE0("Failed to create toolbar\n");
+    return -1; // fail to create
+  }
+
+  m_RTToolBar.SetBarStyle(m_RTToolBar.GetBarStyle() | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC);
+  m_RTToolBar.EnableDocking(CBRS_ALIGN_ANY);
+  EnableDocking(CBRS_ALIGN_ANY);
+  DockControlBar(&m_RTToolBar);
+
   return 0;
 }
\ No newline at end of file
index 170cd0d..ecc5b1a 100755 (executable)
@@ -31,6 +31,9 @@ public:
 
        DECLARE_MESSAGE_MAP()
 
+//Attributes
+protected:
+       CToolBar m_RTToolBar;
 };
 
 #endif // !defined(AFX_OCC_3DCHILDFRAME_H__84879CFC_7EE3_11D7_8632_0060B0EE281E__INCLUDED_)
index f4fd5c5..974db14 100755 (executable)
@@ -25,6 +25,7 @@
 #define IDR_TB_AIS                      149
 #define IDD_GrilleRectangulaire         150
 #define IDD_GrilleCirculaire            151
+#define IDR_RAY_TRACING                 182
 #define IDD_COLORMESH                   552
 #define IDB_coloredmesh                 554
 #define IDC_RICHEDIT_ResultDialog       1001
 #define ID_BUTTON2DGridRectPoints       32779
 #define ID_BUTTON2DGridCircLines        32780
 #define ID_OBJECT_REMOVE                32796
+#define ID_OBJECT_RAY_TRACING           32898
+#define ID_OBJECT_SHADOWS               32899
+#define ID_OBJECT_REFLECTIONS           32900
+#define ID_OBJECT_ANTI_ALIASING         32902
 #define ID_BUTTONZoomAll                40000
 #define ID_OBJECT_ERASE                 40001
 #define ID_BUTTONZoomWin                40002
index 3667b0a..38898aa 100755 (executable)
@@ -67,6 +67,7 @@ IDR_2dCHILDFRAME        BITMAP                  "2dChildFrameTB.bmp"
 IDR_3dCHILDFRAME        BITMAP                  "3dChildFrameTB.bmp"
 IDR_TB_AIS              BITMAP                  "AIS_TB.bmp"
 IDB_coloredmesh         BITMAP                  "coloredm.bmp"
+IDR_RAY_TRACING         BITMAP                  "ToolbarRayTracing.bmp"
 
 /////////////////////////////////////////////////////////////////////////////
 //
@@ -280,6 +281,7 @@ BEGIN
     PUSHBUTTON      "Change dimension color",IDC_DimensionColor,105,156,63,24,BS_MULTILINE
     CONTROL         "",IDC_Flyout,"msctls_trackbar32",TBS_TOP | TBS_TOOLTIPS | WS_TABSTOP,73,112,100,20
 END
+
 IDD_DIALOG_STEREO DIALOGEX 0, 0, 166, 177
 STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
 CAPTION "Configure stereo"
@@ -386,6 +388,14 @@ BEGIN
     BUTTON      ID_OBJECT_DIM
 END
 
+IDR_RAY_TRACING TOOLBAR  20, 20
+BEGIN
+    BUTTON      ID_OBJECT_RAY_TRACING
+    BUTTON      ID_OBJECT_SHADOWS
+    BUTTON      ID_OBJECT_REFLECTIONS
+    BUTTON      ID_OBJECT_ANTI_ALIASING
+END
+
 
 /////////////////////////////////////////////////////////////////////////////
 //
diff --git a/samples/mfc/standard/Common/res/ToolbarRayTracing.bmp b/samples/mfc/standard/Common/res/ToolbarRayTracing.bmp
new file mode 100644 (file)
index 0000000..809af47
Binary files /dev/null and b/samples/mfc/standard/Common/res/ToolbarRayTracing.bmp differ
index 78e53ea..e5f5c8e 100644 (file)
     <None Include="..\..\..\..\Common\res\coloredm.bmp" />
     <None Include="..\..\..\..\Common\res\MainFrame.ico" />
     <None Include="..\..\..\..\Common\res\occ_logo.bmp" />
+    <None Include="..\..\..\..\Common\res\ToolbarRayTracing.bmp" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
index 3a5573c..9dfbb7d 100644 (file)
     <None Include="..\..\..\..\Common\res\occ_logo.bmp">
       <Filter>Resource Files</Filter>
     </None>
+    <None Include="..\..\..\..\Common\res\ToolbarRayTracing.bmp">
+      <Filter>Resource Files</Filter>
+    </None>
   </ItemGroup>
 </Project>
\ No newline at end of file
index 972ded5..246c776 100644 (file)
     <None Include="..\..\..\..\Common\res\coloredm.bmp" />
     <None Include="..\..\..\..\Common\res\MainFrame.ico" />
     <None Include="..\..\..\..\Common\res\occ_logo.bmp" />
+    <None Include="..\..\..\..\Common\res\ToolbarRayTracing.bmp" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
index 1e4879d..8c55ba1 100644 (file)
     <None Include="..\..\..\..\Common\res\occ_logo.bmp">
       <Filter>Resource Files</Filter>
     </None>
+    <None Include="..\..\..\..\Common\res\ToolbarRayTracing.bmp">
+      <Filter>Resource Files</Filter>
+    </None>
   </ItemGroup>
 </Project>
\ No newline at end of file
index c97f860..34c2e39 100644 (file)
     <None Include="..\..\..\..\Common\res\coloredm.bmp" />
     <None Include="..\..\..\..\Common\res\MainFrame.ico" />
     <None Include="..\..\..\..\Common\res\occ_logo.bmp" />
+    <None Include="..\..\..\..\Common\res\ToolbarRayTracing.bmp" />
   </ItemGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
   <ImportGroup Label="ExtensionTargets">
index 1e4879d..8c55ba1 100644 (file)
     <None Include="..\..\..\..\Common\res\occ_logo.bmp">
       <Filter>Resource Files</Filter>
     </None>
+    <None Include="..\..\..\..\Common\res\ToolbarRayTracing.bmp">
+      <Filter>Resource Files</Filter>
+    </None>
   </ItemGroup>
 </Project>
\ No newline at end of file
index 9c5d36a..ab55261 100644 (file)
                                RelativePath="..\..\..\..\Common\res\occ_logo.bmp"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\..\..\Common\res\ToolbarRayTracing.bmp"
+                               >
+                       </File>
                </Filter>
        </Files>
        <Globals>
index 2006d98..16d410e 100644 (file)
                                RelativePath="..\..\..\..\Common\res\occ_logo.bmp"
                                >
                        </File>
+                       <File
+                               RelativePath="..\..\..\..\Common\res\ToolbarRayTracing.bmp"
+                               >
+                       </File>
                </Filter>
        </Files>
        <Globals>