Skip to content

Commit d62a762

Browse files
author
Charles PIGNEROL
committed
Version 5.12.0. vtkFrustumWidget fixes: dynamic calculation of the radius of the tubes delimiting the outline of the planes, problem of disappearance of the scene during interactions such as zoom/rotation.
1 parent 16693a7 commit d62a762

File tree

6 files changed

+178
-2
lines changed

6 files changed

+178
-2
lines changed

cmake/version.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#
44

55
set (VTK_CONTRIB_MAJOR_VERSION "5")
6-
set (VTK_CONTRIB_MINOR_VERSION "11")
6+
set (VTK_CONTRIB_MINOR_VERSION "12")
77
set (VTK_CONTRIB_RELEASE_VERSION "0")
88
set (VTK_CONTRIB_VERSION ${VTK_CONTRIB_MAJOR_VERSION}.${VTK_CONTRIB_MINOR_VERSION}.${VTK_CONTRIB_RELEASE_VERSION})
99

src/VtkContrib/public/VtkContrib/vtkFrustumWidget.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#ifndef VTK_FRUSTUM_WIDGET_H
88
#define VTK_FRUSTUM_WIDGET_H
99

10+
#include "VtkContrib/vtkPolygonFilter.h"
11+
1012
#include <vtkActor.h>
1113
#include <vtk3DWidget.h>
1214
#include <vtkActor.h>
@@ -212,6 +214,7 @@ class vtkFrustumWidget : public vtk3DWidget
212214

213215
/** Le tronc et sa représentation. */
214216
vtkSmartPointer<vtkFrustumSource> _frustum;
217+
vtkSmartPointer<vtkPolygonFilter> _polygonFilter;
215218
vtkSmartPointer<vtkPlanes> _planes;
216219
vtkSmartPointer<vtkPolyDataMapper> _frustumMapper;
217220
vtkSmartPointer<vtkActor> _frustumActor;
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#ifndef VTK_POLYGON_FILTER_H
2+
#define VTK_POLYGON_FILTER_H
3+
4+
5+
#include <vtkPolyDataAlgorithm.h>
6+
#include <vtkIndent.h>
7+
#include <vtkCell.h>
8+
#include <iostream>
9+
10+
11+
/** <P>Filtre permettant d'extraire les polygones d'une instance de vtkPolyData.
12+
* </P>
13+
* @author Charles PIGNEROL, CEA/DAM/DCLC
14+
*/
15+
class vtkPolygonFilter : public vtkPolyDataAlgorithm
16+
{
17+
public :
18+
19+
/** Destructeur : RAS
20+
*/
21+
virtual ~vtkPolygonFilter ( );
22+
23+
/** Instanciation de cette classe.
24+
*/
25+
static vtkPolygonFilter* New ( );
26+
27+
vtkTypeMacro(vtkPolygonFilter,vtkPolyDataAlgorithm);
28+
29+
/**
30+
* Affiche quelques infos sur l'instance.
31+
* @param flux d'impression
32+
* @param indentation utilisée
33+
*/
34+
virtual void PrintSelf (ostream& os, vtkIndent indent);
35+
36+
/**
37+
* Effectue l'extraction.
38+
*/
39+
virtual int RequestData (vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector);
40+
41+
42+
protected :
43+
44+
/** Constructeur.
45+
*/
46+
vtkPolygonFilter ( );
47+
48+
49+
private :
50+
51+
/** Constructeur de copie : interdit. */
52+
vtkPolygonFilter (const vtkPolygonFilter&);
53+
54+
/** Opérateur = : interdit. */
55+
vtkPolygonFilter& operator = (const vtkPolygonFilter&);
56+
}; // class vtkPolygonFilter
57+
58+
59+
#endif // VTK_POLYGON_FILTER_H

src/VtkContrib/vtkFrustumWidget.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,10 +237,12 @@ vtkFrustumWidget::vtkFrustumWidget ( )
237237
: vtk3DWidget ( ), _parallelPlanes ( )
238238
{
239239
_frustum = vtkSmartPointer<vtkFrustumSource>::Take (vtkFrustumSource::New ( ));
240+
_polygonFilter = vtkSmartPointer<vtkPolygonFilter>::Take (vtkPolygonFilter::New ( ));
241+
_polygonFilter->SetInputData (_frustum->GetOutput ( ));
240242
_planes = vtkSmartPointer<vtkPlanes>::Take (vtkPlanes::New ( ));
241243
_frustumMapper = vtkSmartPointer<vtkPolyDataMapper>::Take (vtkPolyDataMapper::New ( ));
242244
_frustumActor = vtkSmartPointer<vtkActor>::Take (vtkActor::New ( ));
243-
_frustumMapper->SetInputConnection (_frustum->GetOutputPort ( ));
245+
_frustumMapper->SetInputData (_polygonFilter->GetOutput ( ));
244246
_frustumActor->SetMapper (_frustumMapper);
245247
_contourFilter = vtkSmartPointer<vtkTubeFilter>::Take (vtkTubeFilter::New ( ));
246248
_contourMapper = vtkSmartPointer<vtkPolyDataMapper>::Take (vtkPolyDataMapper::New ( ));
@@ -312,6 +314,12 @@ void vtkFrustumWidget::SetEnabled (int enabled)
312314
{
313315
if (true == enabled)
314316
{
317+
_polygonFilter->Update ( );
318+
double bounds [6] = { 0., 0., 0., 0., 0., 0. };
319+
GetBounds (bounds);
320+
const double radius = sqrt ((bounds [1] - bounds [0])*(bounds [1] - bounds [0]) + (bounds [3] - bounds [2])*(bounds [3] - bounds [2]) + (bounds [5] - bounds [4])*(bounds [5] - bounds [4])) / 200.;
321+
_contourFilter->SetRadius (radius); // 5.12.0
322+
_contourFilter->Update ( );
315323
GetCurrentRenderer ( )->AddActor (_frustumActor);
316324
GetCurrentRenderer ( )->AddActor (_contourActor);
317325
}
@@ -490,6 +498,7 @@ void vtkFrustumWidget::GetBounds (double bounds [6])
490498
else
491499
{
492500
// frustum->GetBounds (bounds);
501+
// CP : le commentaire ci-après n'est peut être plus vrai depuis l'utilisation de vtkPolygonFilter (v 5.12.0).
493502
/* On n'utilise pas frustum->GetBounds (bounds) car notre polydata contient des lignes qui parfois, de manière non reproductible,
494503
* sortent carrément du domaine observé, à savoir qu'une composante d'une coordonnée peut être de l'ordre de 10E+30 ! Parfois veut ici
495504
* dire environ 1 fois sur 15, et c'est semble-t-il toujours au premier appel de cette fonction. Problème d'initialisation d'une
@@ -638,6 +647,7 @@ void vtkFrustumWidget::CreateDefaultRepresentation ( )
638647
_planes->SetNormals (normals);
639648
_frustum->SetPlanes (_planes);
640649
_frustum->Update ( );
650+
_polygonFilter->Update ( );
641651
// On confère à ce widget le look de la classe vtkImplicitPlaneWidget :
642652
_frustumActor->SetProperty (_planeWidgets [0]->GetPlaneProperty ( ));
643653
} // vtkFrustumWidget::CreateDefaultRepresentation
@@ -692,6 +702,7 @@ void vtkFrustumWidget::Update (vtkFrustumWidget::vtkInternalPlaneWidget* planeWi
692702
_frustum->SetPlanes (_planes);
693703
_frustum->Modified ( );
694704
_frustum->Update ( );
705+
_polygonFilter->Update ( );
695706

696707
// Recentrer les manipulateurs sur leur face :
697708
vtkPolyData* frustum = _frustum->GetOutput ( );
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include "VtkContrib/vtkPolygonFilter.h"
2+
3+
#include <vtkDataSet.h>
4+
#include <vtkCellData.h>
5+
#include <vtkPointData.h>
6+
#include <assert.h>
7+
8+
#include <algorithm>
9+
#include <list>
10+
using namespace std;
11+
12+
13+
vtkPolygonFilter::vtkPolygonFilter ( )
14+
: vtkPolyDataAlgorithm ( )
15+
{
16+
} // vtkPolygonFilter::vtkPolygonFilter
17+
18+
19+
vtkPolygonFilter::vtkPolygonFilter (const vtkPolygonFilter&)
20+
: vtkPolyDataAlgorithm ( )
21+
{
22+
assert (0 && "vtkPolygonFilter copy constructor is not allowed.");
23+
} // vtkPolygonFilter::vtkPolygonFilter
24+
25+
26+
vtkPolygonFilter& vtkPolygonFilter::operator = (const vtkPolygonFilter&)
27+
{
28+
assert (0 && "vtkPolygonFilter operator = is not allowed.");
29+
return *this;
30+
} // vtkPolygonFilter::operator =
31+
32+
33+
vtkPolygonFilter::~vtkPolygonFilter ( )
34+
{
35+
} // vtkPolygonFilter::~vtkPolygonFilter
36+
37+
38+
vtkPolygonFilter* vtkPolygonFilter::New ( )
39+
{
40+
return new vtkPolygonFilter ( );
41+
} // vtkPolygonFilter::New
42+
43+
44+
void vtkPolygonFilter::PrintSelf (ostream& os, vtkIndent indent)
45+
{
46+
Superclass::PrintSelf(os,indent);
47+
} // vtkPolygonFilter::PrintSelf
48+
49+
50+
#define RD_SUCCESS 1
51+
#define RD_FAILURE 0
52+
int vtkPolygonFilter::RequestData (vtkInformation* request, vtkInformationVector** inputVector, vtkInformationVector* outputVector)
53+
{
54+
vtkPolyData* input = GetPolyDataInput (0);
55+
vtkPolyData* output = GetOutput ( );
56+
vtkPoints* pointSet = 0 == input ? 0 : input->GetPoints ( );
57+
vtkCellArray* cells = 0 == input ? 0 : input->GetPolys ( );
58+
if (0 == output)
59+
{
60+
vtkErrorMacro(<<"vtkPolygonFilter::Execute : filter does not have any output.");
61+
return RD_FAILURE;
62+
} // if (0 == output)
63+
if ((0 == input) || (0 == pointSet) || (0 == cells))
64+
{
65+
vtkErrorMacro(<<"vtkPolygonFilter::Execute : filter does not have any input.");
66+
return RD_FAILURE;
67+
} // if (0 == input) || (0 == pointSet) || (0 == cells))
68+
output->Reset ( );
69+
70+
const size_t cellNum = cells->GetNumberOfCells ( );
71+
vtkIdType* cellsPtr = cells->GetPointer ( );
72+
output->SetPoints (pointSet);
73+
output->Allocate (cellNum, cellNum);
74+
for (int i = 0; i < cellNum; i++)
75+
{
76+
const vtkIdType nodeCount = *cellsPtr;
77+
cellsPtr++;
78+
switch (nodeCount)
79+
{
80+
case 3 : output->InsertNextCell (VTK_TRIANGLE, nodeCount, cellsPtr); break;
81+
case 4 : output->InsertNextCell (VTK_QUAD, nodeCount, cellsPtr); break;
82+
} // switch (nodeCount)
83+
cellsPtr += nodeCount;
84+
} // for (i = 0; i < cellNum; i++)
85+
86+
output->GetCellData ( )->PassData (input->GetCellData ( ));
87+
output->Squeeze ( );
88+
89+
return RD_SUCCESS;
90+
} // vtkPolygonFilter::RequestData

versions.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
Version 5.12.0 : 17/10/25
2+
================
3+
4+
Classe vtkPolygonFilter.
5+
6+
Correctifs vtkFrustumWidget :
7+
- le rayon des tubes délimitants le contour des plans est calculé au moment de l'affichage => évite que ces
8+
tubes soient tellement fins qu'on ne les voit pas.
9+
- Dans certains cas à la moindre interaction (zoom/rotation) la scène disparaissait (pb probable de clipping).
10+
Cela semblait provenir des vtkLines du vtkPolyData en sortie de vtkFrustumSource dont certaines composantes
11+
de coordonnées pouvaient être infinies. Problème semble t-il résolu en filtrant avec la classe vtkPolygonFilter.
12+
13+
114
Version 5.11.0 : 03/10/25
215
================
316

0 commit comments

Comments
 (0)