Archived issue #0022877

Draw Harness - add plugin for VIS component

Open CASCADEOCCT:VISclosed41 public notes

Search issues

Description

It is necessary to provide a DRAW plugin library (IVtkTest) with set of commands for initializing the VTK 3D view, basic interactive operations - zoom, rotate, pan, selection, displaying/erasing shapes using VIS component API).

Its sources should be put into VIS component SVN.

Additional information

VIS source files were moved from samples/vtk to src and now VIS compiles with WOK under Windows and Linux.
New DRAW plugin were added for VIS testing (TKIVtkDraw).

List of added packages:

==========================================
IVtk package:

IVtk_Interface.hxx
IVtk_Interface.cxx
IVtk_IShape.hxx
IVtk_IShape.cxx
IVtk_IShapeData.hxx
IVtk_IShapeData.cxx
IVtk_IShapeMesher.hxx
IVtk_IShapeMesher.cxx
IVtk_IShapePickerAlgo.hxx
IVtk_IShapePickerAlgo.cxx
IVtk_IView.hxx
IVtk_IView.cxx
IVtk_Types.hxx

==========================================
IVtkOCC package:

IVtkOCC.hxx
IVtkOCC_SelectableObject.hxx
IVtkOCC_SelectableObject.cxx
IVtkOCC_Shape.hxx
IVtkOCC_Shape.cxx
IVtkOCC_ShapeMesher.hxx
IVtkOCC_ShapeMesher.cxx
IVtkOCC_ShapePickerAlgo.hxx
IVtkOCC_ShapePickerAlgo.cxx
IVtkOCC_ViewerSelector.hxx
IVtkOCC_ViewerSelector.cxx

==========================================
IVtkVTK package:

IVtkVTK_ShapeData.hxx
IVtkVTK_ShapeData.cxx
IVtkVTK_View.hxx
IVtkVTK_View.cxx

==========================================
IVtkTools package:

IVtkTools.hxx
IVtkTools.cxx
IVtkTools_DisplayModeFilter.hxx
IVtkTools_DisplayModeFilter.cxx
IVtkTools_ShapeDataSource.hxx
IVtkTools_ShapeDataSource.cxx
IVtkTools_ShapeObject.hxx
IVtkTools_ShapeObject.cxx
IVtkTools_ShapePicker.hxx
IVtkTools_ShapePicker.cxx
IVtkTools_SubPolyDataFilter.hxx
IVtkTools_SubPolyDataFilter.cxx

==========================================
IVtkDraw package:

IVtkDraw.hxx
IVtkDraw.cxx
IVtkDraw_HighlightAndSelectionPipeline.hxx
IVtkDraw_HighlightAndSelectionPipeline.cxx
IVtkDraw_Interactor.hxx
IVtkDraw_Interactor.cxx

================================================================================

To compile VIS with WOK it's necessary to modify following files in WOK installation directory:

WOK/lib/CSF.edl:

add variables

  @set %CSF_VTK_INCLUDES = "";
  @set %CSF_VTK = "";

WOK/lib/CSF_WNT.edl:

add strings

  @string %CSF_VTK_INCLUDES = " ";
  @string %CSF_VTK = "vtkCommon.lib vtkRendering.lib vtkFiltering.lib vtkGraphics.lib";

WOK/lib/CSF_LIN.edl:

add string

  @set %CSF_VTK = "-lvtkRendering -lvtkCommon -lvtkFiltering -lvtkGraphics";


WOK/site/custom.bat (or use GUI tool for customizing environment) : add path to VTK dir

===============================================================================

New DRAW commands were added:

ivtkinit - creates 3D viewer window
ivtkdisplay - displays named objects
ivtkerase - erases named or all displayed objects
ivtkfit - automatic zoom/panning
ivtksetdispmode - sets display mode for named or all displayed objects
ivtksetselmode - sets selection mode for named or all displayed objects
ivtkmoveto - imitates mouse move to input point
ivtkselect - imitates selection in input point


Public activity

41 archived notes

Participants are labeled by their role within this record.

01Commenter 1
File Attachment 3 (DOC) added
02Commenter 2
Branch CR22877 in occt-products repository is ready for reviewing
03Commenter 3
1. I have slightly modified the text in the attached user's guide in a hope to make it a bit more clear. Please find the adjusted text in another attachment.

2. Usage of VTK smart pointers seems to be not always correct. E.g. you define a type shortcut PRenderer for vtkSmartPointer<vtkRenderer> and then allocate it like this:

PRenderer aRenderer = vtkRenderer::New();

However, the correct version will be:

PRenderer aRenderer = PRenderer::New();

Please find details in http://www.vtk.org/Wiki/VTK/Tutorials/SmartPointers. This concerns almost all other VTK types used in IVtkDraw (vtkRenderWindow, filters etc).

3. I've got a compilation problem in IVtkDraw_Interactor::Enable method on my x64-SEVEN workstation. This is due to the following invocation:

SetWindowLong(this->WindowId, GWL_WNDPROC, (LONG)WndProc);

MSDN states that this function is obsolete and recommends to change it with the following:

SetWindowLongPtr(this->WindowId, GWLP_WNDPROC, (LONG_PTR)WndProc);

4. VERTEX selection mode does not work. This can be reproduced by the following simple script:

ivtkinit
box a 1 1 1
ivtkdisplay a
ivtksetselmode 1 1

This happens because Highlight and Selection DisplayModeFilter instances ignore VTK cells with "Free Vertex" type. As I see, this behavior is configured by calling the corresponding SetDisplaySharedVertices method of IVtkTools_DisplayModeFilter class. I have slightly adjusted VtkSetSelectionMode command to take it into accout.

On the whole, new IVtkDraw package looks quite well from my opinion.

Dear Sergey (SAN),

I have modified IVtkDraw sources according to the mentioned remarks. However, I think that it is worth finalizing the user's guide still.
04Commenter 4
Another remark to proceed: it seems that VIS component is not protected by OCC License yet.
05Commenter 5
I have got more remarks to the sources of IVtkDraw package:

1. Finally, I think it is a bad idea to mix up the usage of VTK smart pointers with raw pointers. As official documentation says, the assignment of a raw pointer to the correspondent smart pointer object does not transfer the ownership to that smart pointer object correctly. That is why the code like

PActor anActor = anActorCollection->GetNextActor();

does not make sense. It only introduces additional unnecessary conversions from raw pointer type to the smart one (PActor is a type definition for vtkSmartPointer<vtkActor>). In order to prevent such a mess I would propose to avoid such type definitions at all. E.g. in the mentioned case it will be

vtkActor* anActor = anActorCollection->GetNextActor();

2. Consider the following case:

box a 1 1 1
psphere b 1
vtkinit
vtkdisplay a
vtkdisplay b
vtksetselmode a 1 1
vtksetselmode b 1 1

This script creates two primitive solids and sets selection mode to VERTEX for both. Now execute the following command:

vtksetselmode b 1 0

This will lead to un-setting the VERTEX selection mode not only for shape "b" but also for shape "a". This issue is caused by the fact that both "a" and "b" presentations utilize the same visualization pipeline and have the same highlight/selection Display Mode filter instance. The latter instance is in-turn responsible
for displaying shared vertices. If we switch off the Free Vertex visibility for "b", the same thing will obviously happen to "a". I would propose not to use such shared pipelines at all.

Instead we can allocate as many pipelines as many shapes we have. This approach will resolve the issue with VERTEX selection mode. Moreover, it will simplify the pipeline's architecture to the minimal required. It will be possible to move the visualization code from IVtkDraw::CreateActor to more suitable place -- the pipeline itself. Finally, I think that having one-to-one correspondence between pipelines and shapes is more natural, less error-prone (as less filtering is going to applied) and easy to maintain.
06Commenter 6
The final reviewed versions of VIS User's Guide and VIS DRAW User's Guide can be found in CR22877 branch of occt-doc.git repository.
07Commenter 7
For VIS sample application and OCCLicense there are now separate Mantis issues #0023390 and #23391.

08Commenter 8
The final set of changes related to correction of #0022901 and #23302 is ready in branch CR22877.

Possibility to run VIS tests in offscreen mode using DRAWEXE -v is not yet implemented, see #23396.

Dear Commenter 1,

Could you please create a set of tests covering the following VIS capabilities:

- Initializing and closing VTK view
- Displaying and erasing OCCT shapes
- Setting display modes for displayed shapes
- Activating and deactivating selection modes for displayed shapes and checking selection results

Then, the tests can be run in "windowed" mode, or at least this is worth trying.
09Commenter 9
Here are the instructions how to build VTK on all supported platforms.

1. Download and/or build cmake utility: http://www.cmake.org/cmake/resources/software.html

2. Download the latest VTK sources: http://www.vtk.org/VTK/resources/software.html#latest

3. Create a separate build directory and run:
- cmake-gui under Windows
- ccmake under Linux

4. Specify the VTK source and build directories in the configuration window, then "Configure".
Under Windows, you will be asked to choose VC++ compiler version to be used among the available ones.

5. Switch to "Advanced" view. Leave most configuration options in default state, paying attention to the following ones:

BUILD_DOCUMENTATION: OFF

BUILD_EXAMPLES: OFF

BUILD_SHARED_LIBS: ON

BUILD_TESTING: OFF

CMAKE_CONFIGURATION_TYPES: Debug;Release

CMAKE_INSTALL_PREFIX: <dir_where_to_install_VTK>

FREETYPE_INCLUDE_DIR_freetype2:
FREETYPE_INCLUDE_DIR_ft2build:
FREETYPE_LIBRARY:
Make sure these variables refer to the same FreeType installation as the one used for building OCCT

GL2PS_INCLUDE_DIR:
GL2PS_LIBRARY:
Make sure these variables refer to the same gl2ps installation as the one used for building OCCT

VTK_USE_64BIT_IDS: ON <- for 64-bit platforms

VTK_USE_FFMPEG_ENCODER: OFF

VTK_USE_GEOVIS: OFF

VTK_USE_GL2PS: ON

VTK_USE_GUISUPPORT: OFF

VTK_USE_OFFSCREEN: OFF

VTK_USE_PARALLEL: ON

VTK_USE_RENDERING: ON

VTK_USE_SYSTEM_FREETYPE: ON

VTK_USE_SYSTEM_GL2PS: ON

VTK_WRAP_JAVA: OFF

VTK_WRAP_PYTHON: OFF

VTK_WRAP_PYTHON_SIP: OFF

VTK_WRAP_TCL: OFF

6. "Configure", then "Generate" (if no errors appear), otherwise correct the errors and "Configure"/"Generate" again.

7. After successful generation of VC++ project files under Windows or Makefiles under Linux simply run the corresponding build tool. No environment script is required, as cmake puts all necessary absolute paths into the projects/Makefiles.

8. NOTE: cmake installs Debug and Release binaries to the same directory, so you might need to rename the binary dir in order to prevent the installed binaries form being overwritten.
After installing VTK in Debug configuration under Windows, you might need to copy VTK .pdb files to the binary installation directory from the build directory manually, sometimes this is not done automatically.
10Commenter 10
Dear Commenter 1,

GIT Branch [archived branch] has been created in the products repository, it includes the changes from outdated CR22877 but it is based on the current master HEAD. This branch also includes correction for #0023495.
It is ready for testing now, even if offscreen rendering is not yet implemented by IVtkDraw.

I kindly ask you to force testing of VIS component, otherwise in some weeks we will have once again to waste time on rebasing.
11Commenter 11
Current sources ported on OCCT 6.7.0 under Windows canb e found in CR22877_1 branch in occt-products.
12Commenter 12
TODO:

1. Build VTK 5.10.1
2. Update WOK 6.7.0 to support VTK as optional OCCT prerequisite (see how OpenCL integration is done, for example)
3. Prepare VIS sources in a branch in OCCT Git, finalize migration to current OCCT development version under Linux.
4. Implement ivtkdump command + support of "virtual window" DRAW mode (offscreen rendering)
5. Correct most critical bugs.
6. Analayze and improve VIS performance
13Commenter 13
Dear san,

the first version of VIS in OCC is ready for review:
- in OCC repository the branch CR22877_1,
- in WOK repository the branch CR22877_1.

14Commenter 14
Dear kgv,

Could you please review the branch CR22877_1 in the WOK repository?
15Commenter 15
The git branch CR22877_2 was added.

The branch consists of :
- TKIvkDraw toolkit, that provides VTK windows in OCC and tcl test commands
- test cases
16Commenter 16
The branch CR22877_2 is to be tested and integrated only after patch for #0024904 is integrated.
17Commenter 17
Dear san,

please review the branch CR22877_2.
18Commenter 18
The patch was updated, rebased on current master, and pushed in CR22877_3.
19Commenter 2
Dear Anastasia,

please consider the following remarks:

+static Standard_Boolean IsEqual (const TopoDS_Shape theLeft,
+                                 const TopoDS_Shape theRight)

Please create hasher structure instead. Handles should be passed by reference.

+#define _WIN32_WINNT 0x0400  // for trackmouseevent support  requires Win95 with IE 3.0 or greater.
+
+#ifdef WNT
+#include <windows.h>

Please use proper macros - _WIN32 for Windows, WNT is deprecated. Move _WIN32_WINNT to #ifdef _WIN32 block.

+static Handle(ShapePipelineMap) GetPipelines()
+{
+  static Handle(ShapePipelineMap) aPLMap;

static const Handle(ShapePipelineMap)& GetPipelines().

+static Handle(PipelinePtr) GetPipeline (const IVtk_IdType& theShapeID)
+{
+  Handle(ShapePipelineMap) aPLMap = GetPipelines();
+
+  if ( !aPLMap->IsBound(theShapeID) )
+  {
+    return NULL;
+  }
+
+  return aPLMap->Find (theShapeID);

Handle(PipelinePtr) aPtr;
GetPipelines()->Find (theShapeID, aPtr);
return aPtr;

+Standard_Integer GenerateId()
+{
+  static int shapesCounter = 0;
+  return shapesCounter++;
+}

static unsigned int shapesCounter = (unsigned int )-1;
return (Standard_Integer )++shapesCounter;

+  vtkActor* anActor;

Please avoid using uninitialized variables.

+    Standard_Integer aMode = atoi(theArgs[2]);

Here and in other places - please use Draw::Atoi() instead.

+    if (strcasecmp (aBufferTypeStr, "rgb") == 0)

Please use TCollection_AsciiString for strings comparison.

+  }
+    else if (aFormat.IsEqual ("pnm"))
+  {
+    anImageWriter = vtkSmartPointer<vtkPNMWriter>::New();
+  }

Indentation.


+void IVtkDraw::Commands (Draw_Interpretor& theCommands)
+{
+ const char *group = "VtkViewer";
+ theCommands.Add("ivtkinit",

No isFirst protection.


+// Created on: 2012-02-03
+//
+// Copyright (c) 2011-2014 OPEN CASCADE SAS

Inconsistent dates.

+#ifndef _Standard_HeaderFile
+#include <Standard.hxx>
+#endif
+#ifndef _Standard_Macro_HeaderFile
+#include <Standard_Macro.hxx>
+#endif

Please remove redundant ifdefs.

+class IVtkDraw
+{
+public:
+
+  void* operator new (size_t, void* theAddress)
+  {
+    return theAddress;
+  }
+
+  void* operator new (size_t theSize)
+  {
+    return Standard::Allocate (theSize);
+  }
+
+  void  operator delete (void* theAddress)
+  {
+    if (theAddress) Standard::Free((Standard_Address&) theAddress);
+  }

Please use DEFINE_STANDARD_ALLOC instead.

+  for (ShapePipelineMap::Iterator anIt (*theMap.operator->()); anIt.More(); anIt.Next())

*theMap is enough.

+  Handle(Aspect_Window) GetOCCWindow() const;

const reference.

+Standard_Boolean IVtkDraw_Interactor::IsEnabled()

const method.

+  anInteractor = (IVtkDraw_Interactor *)GetWindowLong (theHWnd, GWLP_USERDATA);

GetWindowLongPtr

reinterpret_cast<XConfigureEvent *>(&anEvent)

Please access union XEvent options without casts - like anEvent.xconfigure.

+#ifdef WNT
+  HWND               WindowId;
+  Standard_Integer   MouseInWindow;
+#else
+  Window           WindowId;
+  Display          *DisplayId;
+  Standard_Boolean isLeftButtonPressed;
+#endif

Class IVtkDraw_Interactor fields are not initialized within constructor.
20Commenter 20
The branch CR22877_3 was updated according to last remarks.
21Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
22Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
23Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
24Commenter 24
To be migrated to VTK 6.1.0 - see #0024904.

25Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
26Commenter 3
Branch [archived branch] has been created by Participant.

[revision removed]
27Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
28Commenter 28
The patch was ported to VTK 6.1.0 and rebased on current master.

Dear san,

could you please review the branch CR22877_3?
29Commenter 2
Dear Commenter 1,

please test all patches related to integration of VIS component (component itself, Draw plugin / tests, patch for WOK introducing new dependency).
30Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
31Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
32Commenter 3
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: aba
Date: Wed Sep 3 17:37:52 2014 +0400

    ivtkdump virtual mode correction.

33Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
34Commenter 3
Branch [archived branch] has been updated forcibly by Participant.

[revision removed]
35Commenter 3
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: aba
Date: Fri Sep 5 17:19:14 2014 +0400

    Corrected offscreen rendering mode.

36Commenter 3
Branch [archived branch] has been updated by Participant.

[revision removed]


Detailed log of new commits:

Author: aba
Date: Mon Sep 8 14:04:02 2014 +0400

    Moved vinit command from /v3d/begin script to avoid unused occ view in ivtk tests.

37Commenter 37
Dear ssv,

Due to VIS integration on OCC, documentation for VIS is to be provided.

I have updated attached documentation in track mode and upload it in Attachment 1 (DOC).

Could you please revise it and provide remarks if any?
38Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
39Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
40Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]
41Commenter 3
Branch [archived branch] has been deleted by Participant.

[revision removed]

Related records