Skip to content

Commit d02f763

Browse files
author
Charles PIGNEROL
committed
Pre-release 5.9.0. Improvements to the vtkViewCubeActor class: a second click on a face cancels the roll, and the text is pressed as close as possible to the faces.
1 parent 8e7a8ee commit d02f763

File tree

4 files changed

+83
-31
lines changed

4 files changed

+83
-31
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 "8")
6+
set (VTK_CONTRIB_MINOR_VERSION "9")
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/vtkViewCubeActor.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <vtkPropAssembly.h>
1010
#include <vtkActor.h>
11+
#include <vtkDoubleArray.h>
1112
#include <vtkPolyData.h>
1213
#include <vtkPolyDataMapper.h>
1314
#include <vtkCellPicker.h>
@@ -117,12 +118,18 @@ class vtkViewCubeActor : public vtkPropAssembly
117118
/** Le picking sur les faces du ViewCube. */
118119
vtkSmartPointer<vtkCellPicker> CellPicker;
119120

121+
/** La dernière face pickée. */
122+
unsigned char LastPickedFace;
123+
120124
/** Les labels. */
121125
vtkSmartPointer<vtkVectorText> XPlusVectorText, XMinusVectorText, YPlusVectorText, YMinusVectorText, ZPlusVectorText, ZMinusVectorText;
122126
vtkSmartPointer<vtkActor> XPlusActor, XMinusActor, YPlusActor, YMinusActor, ZPlusActor, ZMinusActor;
123127

128+
/** Les vecteurs "orientation vers le haut". */
129+
vtkSmartPointer<vtkDoubleArray> ViewUpVectors;
130+
124131
/** L'éventuelle transformation utilisateur. */
125-
vtkTransform *Transform;
132+
vtkTransform *Transform;
126133
}; // class vtkViewCubeActor
127134

128135

src/VtkContrib/vtkViewCubeActor.cpp

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "VtkContrib/vtkFloatingPointType.h"
33
#include "VtkContrib/vtkTrihedron.h"
44

5+
#include <vtkCellData.h>
56
#include <vtkPolyDataMapper.h>
67
#include <vtkPolyData.h>
78
#include <vtkProperty.h>
@@ -99,18 +100,22 @@ void vtkViewCubeActorPickCallback::Execute (vtkObject* caller, unsigned long eve
99100
// ====================================== LA CLASSE vtkViewCubeActor ======================================
100101

101102
vtkViewCubeActor::vtkViewCubeActor ( )
102-
: vtkPropAssembly ( ), Renderer (0), DrivenRenderer (0), CubePolyData ( ), CubeActor ( ), CubePolyDataMapper ( ), CellPicker ( ),
103+
: vtkPropAssembly ( ), Renderer (0), DrivenRenderer (0), CubePolyData ( ), CubeActor ( ), CubePolyDataMapper ( ), CellPicker ( ), LastPickedFace ((unsigned char)-1),
103104
XPlusVectorText ( ), XMinusVectorText ( ), YPlusVectorText ( ), YMinusVectorText ( ), ZPlusVectorText ( ), ZMinusVectorText ( ),
104-
XPlusActor ( ), XMinusActor ( ), YPlusActor ( ), YMinusActor ( ), ZPlusActor ( ), ZMinusActor ( ),
105+
XPlusActor ( ), XMinusActor ( ), YPlusActor ( ), YMinusActor ( ), ZPlusActor ( ), ZMinusActor ( ), ViewUpVectors ( ),
105106
Transform (0)
106107
{
107108
CubePolyData = vtkSmartPointer<vtkPolyData>::New ( );
108109
CubeActor = vtkSmartPointer<vtkActor>::New ( );
109110
CubePolyDataMapper = vtkSmartPointer<vtkPolyDataMapper>::New ( );
110111
assert (0 != CubePolyData.Get ( ));
112+
assert (0 != CubePolyData->GetCellData ( ));
111113
assert (0 != CubeActor.Get ( ));
112114
assert (0 != CubePolyDataMapper.Get ( ));
113115
CubePolyData->Initialize ( );
116+
ViewUpVectors = vtkSmartPointer<vtkDoubleArray>::New ( );
117+
ViewUpVectors->SetName ("ViewUp");
118+
ViewUpVectors->SetNumberOfComponents (3);
114119
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New ( );
115120
assert (0 != points.Get ( ));
116121
points->SetNumberOfPoints (24);
@@ -161,44 +166,61 @@ vtkViewCubeActor::vtkViewCubeActor ( )
161166
cellArray->Initialize ( );
162167
idsArray->Initialize ( );
163168
idsArray->SetNumberOfValues (5 * 6 + 5 * 12 + 4 * 8); // Faces + jonctions quads + triangles
169+
CubePolyData->GetCellData ( )->SetVectors (ViewUpVectors);
164170
vtkIdType* cellsPtr = idsArray->GetPointer (0);
165171
size_t pos = 0;
166172
cellsPtr [pos++] = 4; cellsPtr [pos++] = 0; cellsPtr [pos++] = 1; cellsPtr [pos++] = 2; cellsPtr [pos++] = 3; // Bas
173+
ViewUpVectors->InsertNextTuple3 (0., 0., 1.);
167174
cellsPtr [pos++] = 4; cellsPtr [pos++] = 4; cellsPtr [pos++] = 5; cellsPtr [pos++] = 6; cellsPtr [pos++] = 7; // Droite
175+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
168176
cellsPtr [pos++] = 4; cellsPtr [pos++] = 8; cellsPtr [pos++] = 9; cellsPtr [pos++] = 10; cellsPtr [pos++] = 11; // Haut
177+
ViewUpVectors->InsertNextTuple3 (0., 0., 1.);
169178
cellsPtr [pos++] = 4; cellsPtr [pos++] = 15; cellsPtr [pos++] = 14; cellsPtr [pos++] = 13; cellsPtr [pos++] = 12; // Gauche
179+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
170180
cellsPtr [pos++] = 4; cellsPtr [pos++] = 19; cellsPtr [pos++] = 18; cellsPtr [pos++] = 17; cellsPtr [pos++] = 16; // Arrière
181+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
171182
cellsPtr [pos++] = 4; cellsPtr [pos++] = 20; cellsPtr [pos++] = 21; cellsPtr [pos++] = 22; cellsPtr [pos++] = 23; // Avant
172-
// cellsPtr [pos++] = 4; cellsPtr [pos++] = 0; cellsPtr [pos++] = 1; cellsPtr [pos++] = 17; cellsPtr [pos++] = 16; // Bas-Ar
173-
cellsPtr [pos++] = 4; cellsPtr [pos++] = 16; cellsPtr [pos++] = 17; cellsPtr [pos++] = 1; cellsPtr [pos++] = 0; // Bas-Ar
183+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
184+
cellsPtr [pos++] = 4; cellsPtr [pos++] = 16; cellsPtr [pos++] = 17; cellsPtr [pos++] = 1; cellsPtr [pos++] = 0; // Bas-Ar
185+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
174186
cellsPtr [pos++] = 4; cellsPtr [pos++] = 1; cellsPtr [pos++] = 4; cellsPtr [pos++] = 7; cellsPtr [pos++] = 2; // Bas-D
187+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
175188
cellsPtr [pos++] = 4; cellsPtr [pos++] = 3; cellsPtr [pos++] = 2; cellsPtr [pos++] = 21; cellsPtr [pos++] = 20; // Bas-Av
189+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
176190
cellsPtr [pos++] = 4; cellsPtr [pos++] = 12; cellsPtr [pos++] = 0; cellsPtr [pos++] = 3; cellsPtr [pos++] = 15; // Bas-G
177-
// cellsPtr [pos++] = 4; cellsPtr [pos++] = 8; cellsPtr [pos++] = 9; cellsPtr [pos++] = 19; cellsPtr [pos++] = 18; // Haut-Ar
178-
cellsPtr [pos++] = 4; cellsPtr [pos++] = 18; cellsPtr [pos++] = 19; cellsPtr [pos++] = 9; cellsPtr [pos++] = 8; // Haut-Ar
179-
// cellsPtr [pos++] = 4; cellsPtr [pos++] = 6; cellsPtr [pos++] = 11; cellsPtr [pos++] = 8; cellsPtr [pos++] = 5; // Haut-D
180-
cellsPtr [pos++] = 4; cellsPtr [pos++] = 5; cellsPtr [pos++] = 8; cellsPtr [pos++] = 11; cellsPtr [pos++] = 6; // Haut-D
191+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
192+
cellsPtr [pos++] = 4; cellsPtr [pos++] = 18; cellsPtr [pos++] = 19; cellsPtr [pos++] = 9; cellsPtr [pos++] = 8; // Haut-Ar
193+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
194+
cellsPtr [pos++] = 4; cellsPtr [pos++] = 5; cellsPtr [pos++] = 8; cellsPtr [pos++] = 11; cellsPtr [pos++] = 6; // Haut-D
195+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
181196
cellsPtr [pos++] = 4; cellsPtr [pos++] = 11; cellsPtr [pos++] = 10; cellsPtr [pos++] = 23; cellsPtr [pos++] = 22; // Haut-Av
182-
// cellsPtr [pos++] = 4; cellsPtr [pos++] = 10; cellsPtr [pos++] = 14; cellsPtr [pos++] = 13; cellsPtr [pos++] = 9; // Haut-G
183-
cellsPtr [pos++] = 4; cellsPtr [pos++] = 9; cellsPtr [pos++] = 13; cellsPtr [pos++] = 14; cellsPtr [pos++] = 10; // Haut-G
184-
// cellsPtr [pos++] = 4; cellsPtr [pos++] = 17; cellsPtr [pos++] = 4; cellsPtr [pos++] = 5; cellsPtr [pos++] = 18; // Ar-D
185-
cellsPtr [pos++] = 4; cellsPtr [pos++] = 18; cellsPtr [pos++] = 5; cellsPtr [pos++] = 4; cellsPtr [pos++] = 17; // Ar-D
197+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
198+
cellsPtr [pos++] = 4; cellsPtr [pos++] = 9; cellsPtr [pos++] = 13; cellsPtr [pos++] = 14; cellsPtr [pos++] = 10; // Haut-G
199+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
200+
cellsPtr [pos++] = 4; cellsPtr [pos++] = 18; cellsPtr [pos++] = 5; cellsPtr [pos++] = 4; cellsPtr [pos++] = 17; // Ar-D
201+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
186202
cellsPtr [pos++] = 4; cellsPtr [pos++] = 7; cellsPtr [pos++] = 6; cellsPtr [pos++] = 22; cellsPtr [pos++] = 21; // Av-D
187-
// cellsPtr [pos++] = 4; cellsPtr [pos++] = 19; cellsPtr [pos++] = 13; cellsPtr [pos++] = 12; cellsPtr [pos++] = 16; // Ar-G
188-
cellsPtr [pos++] = 4; cellsPtr [pos++] = 16; cellsPtr [pos++] = 12; cellsPtr [pos++] = 13; cellsPtr [pos++] = 19; // Ar-G
203+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
204+
cellsPtr [pos++] = 4; cellsPtr [pos++] = 16; cellsPtr [pos++] = 12; cellsPtr [pos++] = 13; cellsPtr [pos++] = 19; // Ar-G
205+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
189206
cellsPtr [pos++] = 4; cellsPtr [pos++] = 14; cellsPtr [pos++] = 15; cellsPtr [pos++] = 20; cellsPtr [pos++] = 23; // Av-G
207+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
190208
cellsPtr [pos++] = 3; cellsPtr [pos++] = 10; cellsPtr [pos++] = 14; cellsPtr [pos++] = 23; // Av-H-G
209+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
191210
cellsPtr [pos++] = 3; cellsPtr [pos++] = 22; cellsPtr [pos++] = 6; cellsPtr [pos++] = 11; // Av-H-D
211+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
192212
cellsPtr [pos++] = 3; cellsPtr [pos++] = 3; cellsPtr [pos++] = 20; cellsPtr [pos++] = 15; // Av-B-G
213+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
193214
cellsPtr [pos++] = 3; cellsPtr [pos++] = 2; cellsPtr [pos++] = 7; cellsPtr [pos++] = 21; // Av-B-D
194-
// cellsPtr [pos++] = 3; cellsPtr [pos++] = 9; cellsPtr [pos++] = 13; cellsPtr [pos++] = 19; // Ar-H-G
195-
cellsPtr [pos++] = 3; cellsPtr [pos++] = 19; cellsPtr [pos++] = 13; cellsPtr [pos++] = 9; // Ar-H-G
196-
// cellsPtr [pos++] = 3; cellsPtr [pos++] = 18; cellsPtr [pos++] = 5; cellsPtr [pos++] = 8; // Ar-H-D
197-
cellsPtr [pos++] = 3; cellsPtr [pos++] = 8; cellsPtr [pos++] = 5; cellsPtr [pos++] = 18; // Ar-H-D
198-
// cellsPtr [pos++] = 3; cellsPtr [pos++] = 0; cellsPtr [pos++] = 16; cellsPtr [pos++] = 12; // Ar-B-G
199-
cellsPtr [pos++] = 3; cellsPtr [pos++] = 12; cellsPtr [pos++] = 16; cellsPtr [pos++] = 0; // Ar-B-G
200-
// cellsPtr [pos++] = 3; cellsPtr [pos++] = 1; cellsPtr [pos++] = 4; cellsPtr [pos++] = 17; // Ar-B-D
201-
cellsPtr [pos++] = 3; cellsPtr [pos++] = 17; cellsPtr [pos++] = 4; cellsPtr [pos++] = 7; // Ar-B-D
215+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
216+
cellsPtr [pos++] = 3; cellsPtr [pos++] = 19; cellsPtr [pos++] = 13; cellsPtr [pos++] = 9; // Ar-H-G
217+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
218+
cellsPtr [pos++] = 3; cellsPtr [pos++] = 8; cellsPtr [pos++] = 5; cellsPtr [pos++] = 18; // Ar-H-D
219+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
220+
cellsPtr [pos++] = 3; cellsPtr [pos++] = 12; cellsPtr [pos++] = 16; cellsPtr [pos++] = 0; // Ar-B-G
221+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
222+
cellsPtr [pos++] = 3; cellsPtr [pos++] = 17; cellsPtr [pos++] = 4; cellsPtr [pos++] = 7; // Ar-B-D
223+
ViewUpVectors->InsertNextTuple3 (0., 1., 0.);
202224
cellArray->SetCells (6 + 12 + 8, idsArray);
203225
CubePolyData->SetPolys (cellArray);
204226
idsArray->Delete ( ); idsArray = 0;
@@ -246,12 +268,13 @@ cellsPtr [pos++] = 3; cellsPtr [pos++] = 17; cellsPtr [pos++] = 4; cellsPtr [pos
246268
YMinusActor->SetOrigin (0.5, 0.5, 0.5);
247269
ZPlusActor->SetOrigin (0.5, 0.5, 0.5);
248270
ZMinusActor->SetOrigin (0.5, 0.5, 0.5);
249-
XPlusActor->AddPosition (0.7, 0., textWidthScaled);
250-
XMinusActor->AddPosition (-0.7, 0., -textWidthScaled);
251-
YPlusActor->AddPosition (-textWidthScaled, 0.7, 0.);
252-
YMinusActor->AddPosition (-textWidthScaled, -0.7, 0.);
253-
ZPlusActor->AddPosition (-textWidthScaled, 0., 0.7);
254-
ZMinusActor->SetPosition (textWidthScaled, 0., -0.7);
271+
const double position = 0.651; // La bonne position pour que le texte soit collé au plus près de la face associée
272+
XPlusActor->AddPosition (position, 0., textWidthScaled);
273+
XMinusActor->AddPosition (-position, 0., -textWidthScaled);
274+
YPlusActor->AddPosition (-textWidthScaled, position, 0.);
275+
YMinusActor->AddPosition (-textWidthScaled, -position, 0.);
276+
ZPlusActor->AddPosition (-textWidthScaled, 0., position);
277+
ZMinusActor->SetPosition (textWidthScaled, 0., -position);
255278
XPlusActor->SetOrientation (0, 90, 0);
256279
XMinusActor->SetOrientation (0, -90, 0);
257280
YPlusActor->SetOrientation (-90, 0, 0);
@@ -302,7 +325,7 @@ cellsPtr [pos++] = 3; cellsPtr [pos++] = 17; cellsPtr [pos++] = 4; cellsPtr [pos
302325

303326

304327
vtkViewCubeActor::vtkViewCubeActor (const vtkViewCubeActor&)
305-
: vtkPropAssembly ( ), Renderer (0), DrivenRenderer (0), CubePolyData ( ), CubeActor ( ), CubePolyDataMapper ( ), CellPicker ( ),
328+
: vtkPropAssembly ( ), Renderer (0), DrivenRenderer (0), CubePolyData ( ), CubeActor ( ), CubePolyDataMapper ( ), CellPicker ( ), LastPickedFace ((unsigned char)-1),
306329
XPlusVectorText ( ), XMinusVectorText ( ), YPlusVectorText ( ), YMinusVectorText ( ), ZPlusVectorText ( ), ZMinusVectorText ( ),
307330
XPlusActor ( ), XMinusActor ( ), YPlusActor ( ), YMinusActor ( ), ZPlusActor ( ), ZMinusActor ( ),
308331
Transform (0)
@@ -545,6 +568,7 @@ void vtkViewCubeActor::PickCallback (int x, int y)
545568

546569
if (0 != CellPicker->Pick (x, y, 0, Renderer))
547570
{
571+
cout << "LAST=" << (unsigned long)LastPickedFace << "PICKED=" << CellPicker->GetCellId ( ) << endl;
548572
double* normal = CellPicker->GetPickNormal ( );
549573
vtkMath::Normalize( normal);
550574
vtkCamera* camera = DrivenRenderer->GetActiveCamera ( );
@@ -556,11 +580,24 @@ void vtkViewCubeActor::PickCallback (int x, int y)
556580
const double ypos = focalPoint [1] + normal [1] * distance;
557581
const double zpos = focalPoint [2] + normal [2] * distance;
558582
camera->SetPosition (xpos, ypos, zpos);
583+
// if (CellPicker->GetCellId ( ) == LastPickedFace)
584+
{
585+
assert (0 != CubePolyData);
586+
assert (0 != CubePolyData->GetCellData ( ));
587+
assert (0 != CubePolyData->GetCellData ( )->GetVectors ( ));
588+
cout << "NUMBER OF TUPLES=" << CubePolyData->GetCellData ( )->GetVectors ( )->GetNumberOfTuples ( ) << " CELL ID=" << CellPicker->GetCellId ( ) << endl;
589+
assert (CellPicker->GetCellId ( ) < CubePolyData->GetCellData ( )->GetVectors ( )->GetNumberOfTuples ( ));
590+
double* viewup = CubePolyData->GetCellData ( )->GetVectors ( )->GetTuple (CellPicker->GetCellId ( ));
591+
cout << "VIEWUP=(" << viewup [0] << ", " << viewup [1] << ", " << viewup [2] << ")" << endl;
592+
camera->SetViewUp (viewup);
593+
camera->SetRoll (0.);
594+
} // if (CellPicker->GetCellId ( ) == LastPickedFace)
559595
camera->ComputeViewPlaneNormal ( );
560596
DrivenRenderer->ResetCameraClippingRange ( );
561597
if (0 != DrivenRenderer->GetRenderWindow ( ))
562598
DrivenRenderer->GetRenderWindow ( )->Render ( );
563599
} // if (0 != camera)
600+
LastPickedFace = CellPicker->GetCellId ( );
564601
} // if (0 != CellPicker->Pick (x, y, 0, Renderer))
565602
} // vtkViewCubeActor::PickCallback
566603

versions.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
Version 5.9.0 : 11/04/25
2+
===============
3+
4+
Améliorations de la classe vtkViewCubeActor :
5+
- Un second clic sur une face provoque l'annulation du roulis
6+
- Le texte est plaqué au plus près des faces
7+
8+
19
Version 5.8.0 : 04/03/25
210
===============
311

0 commit comments

Comments
 (0)