1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
|
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2025 Univ. Grenoble Alpes, CNRS, Grenoble INP - UGA, TIMC, 38000 Grenoble, France
*
* Visit http://camitk.imag.fr for more information
*
* This file is part of CamiTK.
*
* CamiTK is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
*
* CamiTK is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with CamiTK. If not, see <http://www.gnu.org/licenses/>.
*
* $CAMITK_LICENCE_END$
****************************************************************************/
// -- Core stuff
#include "PlaneC.h"
// -- VTK stuff
// disable warning generated by clang about the surrounded headers
#include "CamiTKDisableWarnings"
#include <vtkProperty.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include "CamiTKReEnableWarnings"
#include <vtkPlaneSource.h>
#include <vtkPolyData.h>
#include <vtkTransform.h>
#include <vtkAbstractTransform.h>
#include <vtkPlanes.h>
#include <vtkSmartPointer.h>
namespace camitk {
//--------------------Constructor---------------------
PlaneC::PlaneC() :
plane {vtkSmartPointer<vtkPlaneSource>::New()},
planeMapper{vtkSmartPointer<vtkPolyDataMapper>::New()} {
// create the mapper;
planeMapper->SetInputConnection(plane->GetOutputPort());
// creates the actor in order to give to the InteractiveViewer
planeActor = vtkSmartPointer<vtkActor>::New();
planeActor->SetMapper(planeMapper);
planeActor->PickableOff();
// Properties of the actor
aProp = vtkSmartPointer<vtkProperty>::New();
// clear the transformation data
clear();
// set the default visualization mode
setVisuPlane();
}
//--------------------Destructor---------------------
PlaneC::~PlaneC() {
//TODO
}
//--------------------Set Visualization of Plane---------------------
void PlaneC::setVisuPlane() {
//Initialize properties of the actor associated to the vtkPlaneSource
aProp->SetColor(0.0, 0.0, 1.0);
aProp->SetOpacity(0.1);
//Visualization in wireframe
aProp->SetRepresentationToWireframe();
planeActor->SetProperty(aProp);
planeActor->ApplyProperties();
}
//--------------------Set Visualization Of Active Plane in red---------------------
void PlaneC::setVisuActivePlane() {
//Change properties of the actor associated to the vtkPlaneSource
aProp->SetColor(1.0, 0.0, 0.0);//color red
aProp->SetOpacity(0.2);
//Visualization in surface
aProp->SetRepresentationToSurface();
planeActor->SetProperty(aProp);
planeActor->ApplyProperties();
}
//--------------------Set Visualization Of Active Plane in blue---------------------
void PlaneC::setVisuActivePlaneOff() {
//Change properties of the actor associated to the vtkPlaneSource
aProp->SetColor(0.0, 0.0, 1.0);//color blue
aProp->SetOpacity(0.1);
//Visualization in surface
aProp->SetRepresentationToSurface();
planeActor->SetProperty(aProp);
planeActor->ApplyProperties();
}
//--------------------Reset the Plane of the View---------------------
void PlaneC::clear() {
for (double& value : transformation) {
value = 0.0;
}
translation = 0.0;
angle1 = 0.0; // no angle when I start
angle2 = 0.0;
translation1 = 0.0;
// Initialization by default
plane->SetOrigin(0.0, 0.0, 0.0);
plane->SetPoint1(0.0, 1.0, 0.0);
plane->SetPoint2(0.0, 0.0, 1.0);
}
//--------------------getActor----------
vtkSmartPointer<vtkActor> PlaneC::getActor() {
return planeActor;
}
//--------------------Initialize a plane with PlaneCtype axis as normal----------
void PlaneC::init(PlaneC::PlaneCType type, double* bounds) {
setOrigin(bounds[0], bounds[2], bounds[4]);
switch (type) {
case X_MAX:
setXAxisPoint(bounds[0], bounds[3], bounds[4]);
setYAxisPoint(bounds[0], bounds[2], bounds[5]);
setTranslationMaxInPercent(bounds[1] - bounds[0]);
translatePlaneX();
break;
case Y_MIN:
setXAxisPoint(bounds[1], bounds[2], bounds[4]);
setYAxisPoint(bounds[0], bounds[2], bounds[5]);
break;
case Y_MAX:
setXAxisPoint(bounds[0], bounds[2], bounds[5]);
setYAxisPoint(bounds[1], bounds[2], bounds[4]);
setTranslationMaxInPercent(bounds[3] - bounds[2]);
translatePlaneY();
break;
case Z_MIN:
setXAxisPoint(bounds[0], bounds[3], bounds[4]);
setYAxisPoint(bounds[1], bounds[2], bounds[4]);
break;
case Z_MAX:
setXAxisPoint(bounds[1], bounds[2], bounds[4]);
setYAxisPoint(bounds[0], bounds[3], bounds[4]);
setTranslationMaxInPercent(bounds[5] - bounds[4]);
translatePlaneZ();
break;
case X_MIN:
case UNDEFINED:
default:
setXAxisPoint(bounds[0], bounds[2], bounds[5]);
setYAxisPoint(bounds[0], bounds[3], bounds[4]);
break;
}
}
//--------------------Translate the Plane on Xaxis---------------------
void PlaneC::translatePlaneX() {
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
double a = (translation - translation1);
translation1 = translation;
t->Translate(a, 0, 0);
double tab[3];
plane->GetCenter(tab);
//change the coordinates of the Plane center and all the plane is translated
t->TransformPoint(tab, tab);
plane->SetCenter(tab);
t->Update();
}
//--------------------Translate the Plane on Yaxis---------------------
void PlaneC::translatePlaneY() {
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
double a = translation - translation1;
translation1 = translation;
t->Translate(0, a, 0);
double tab[3];
plane->GetCenter(tab);
//change the coordinates of the Plane center and all the plane is translated
t->TransformPoint(tab, tab);
plane->SetCenter(tab);
t->Update();
}
//--------------------Translate the Plane on Zaxis---------------------
void PlaneC::translatePlaneZ() {
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
double a = translation - translation1;
translation1 = translation;
t->Translate(0, 0, a);
double tab[3];
plane->GetCenter(tab);
//change the coordinates of the Plane center and all the plane is translated
t->TransformPoint(tab, tab);
plane->SetCenter(tab);
t->Update();
}
//--------------------Rotation around Axe1---------------------
void PlaneC ::rotationAxe1() {
//coordinates of the origin
double tabO[3];
//coordinates of the center
double tabC[3];
//coordinates of the Point1
double tabP[3];
//coordinates of the Normal
double tabN[3];
//coordinates of the vector for the rotation
double tab[3];
//Initialization of each point
plane->GetCenter(tabC);
plane->GetOrigin(tabO);
plane->GetPoint1(tabP);
plane->GetNormal(tabN);
//Initialization of the vector with the Axis1
for (unsigned int i = 0; i < 3; i++) {
tab[i] = tabP[i] - tabO[i];
}
// rotate with the difference between what I want (ang) and the current angle (angle1)
double differenceAngle = transformation[1] - angle1;
// if this rotation is not too small
if (fabs(differenceAngle) > 0.5) {
vtkSmartPointer<vtkTransform> transfo = vtkSmartPointer<vtkTransform>::New();
//Initialization of the transfo with an angle and the vector
transfo->RotateWXYZ(double(differenceAngle), tab);
// record the new angle
angle1 = transformation[1];
//Apply the rotation to the normal and all the plane will rotate
transfo->TransformPoint(tabN, tabN);
plane->SetNormal(tabN);
plane->Update();
transfo->Update();
}
}
//--------------------Rotation around Axe2---------------------
void PlaneC ::rotationAxe2() {
//coordinates of the origin
double tabO[3];
//coordinates of the center
double tabC[3];
//coordinates of the Point2
double tabP[3];
//coordinates of the Normal
double tabN[3];
//coordinates of the vector for the rotation
double tab[3];
//Initialization of each point
plane->GetCenter(tabC);
plane->GetOrigin(tabO);
plane->GetPoint2(tabP);
plane->GetNormal(tabN);
//Initialization of the vector with the Axis2
for (int i = 0; i < 3; i++) {
tab[i] = tabP[i] - tabO[i];
}
// rotate with the difference between what I want (ang) and the current angle (angle2)
double differenceAngle = (double)transformation[2] - (double)angle2;
// if this rotation is not too small
if (fabs(differenceAngle) > 0.5) {
vtkSmartPointer<vtkTransform> transfo = vtkSmartPointer<vtkTransform>::New();
//Initialization of the transfo with an angle and the vector
transfo->RotateWXYZ(differenceAngle, tab);
// record the new angle
angle2 = transformation[2];
//Apply the rotation to the normal and all the plane will rotate
transfo->TransformPoint(tabN, tabN);
plane->SetNormal(tabN);
plane->Update();
transfo->Update();
}
}
//--------------------Set the transformation---------------------
void PlaneC ::setTransfoPercentToRealValue(double* tab, double min, double max) {
for (int i = 0; i < 3; i++) {
transformation[i] = tab[i];
}
translation = transformation[0] * (max - min) / 100;
}
//--------------------Get the transformation---------------------
void PlaneC::getTransformationInPercent(double* t, double* r1, double* r2) {
*t = transformation[0];
*r1 = transformation[1];
*r2 = transformation[2];
}
//--------------------Set the translation---------------------
void PlaneC::setTranslationMaxInPercent(double trans) {
translation = trans;
transformation[0] = 100;
}
//--------------------Get the origin---------------------
void PlaneC::getOrigin(double* tab) {
plane->GetOrigin(tab);
}
//--------------------Get the normal---------------------
void PlaneC::getNormal(double* tab) {
plane->GetNormal(tab);
}
//--------------------Set the origin---------------------
void PlaneC::setOrigin(double x, double y, double z) {
plane->SetOrigin(x, y, z);
}
//--------------------setXAxisPoint---------------------
void PlaneC::setXAxisPoint(double x, double y, double z) {
plane->SetPoint1(x, y, z);
}
//--------------------setYAxisPoint---------------------
void PlaneC::setYAxisPoint(double x, double y, double z) {
plane->SetPoint2(x, y, z);
}
}
|