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
|
/*****************************************************************************
* $CAMITK_LICENCE_BEGIN$
*
* CamiTK - Computer Assisted Medical Intervention ToolKit
* (c) 2001-2014 UJF-Grenoble 1, CNRS, TIMC-IMAG UMR 5525 (GMCAO)
*
* 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$
****************************************************************************/
// pml/lml
#include <pml/Atom.h>
#include <pml/StructuralComponent.h>
#include <pml/Cell.h>
#include <pml/StructuralComponentProperties.h>
#include <pml/PhysicalModel.h>
#include <pml/Cell.h>
#include <pml/Atom.h>
#include <pml/StructuralComponent.h>
#include <pml/MultiComponent.h>
#include "CellDC.h"
#include "CellDCProperties.h"
#include "AtomDC.h"
#include "PMManagerDC.h"
// camiTK
#include <InteractiveViewer.h>
#include <Geometry.h>
using namespace camitk;
// Qt
#include <QPixmap>
// vtk includes
#include <vtkUnstructuredGrid.h>
#include <vtkPolyData.h>
#include <vtkPoints.h>
#include <vtkTransformFilter.h>
#include <vtkDoubleArray.h>
#include <vtkSmartPointer.h>
// -------------------- default constructor --------------------
CellDC::CellDC(camitk::Component *parent, PMManagerDC * pmManagerDC, Cell *theCell) : StructuralComponentDC(parent, pmManagerDC, theCell, true), myCell(theCell) {
// call to the SCDC constructor with a third parameter to delay the initialization of the representation, i.e. the build of the Geometry
// create a proper name
QString name = dynamic_cast<Structure *>(theCell)->getName().c_str();
if (name.isEmpty()) {
// no name -> label is the cell nr
name = QString::number(theCell->getIndex());
}
camitk::Component::setName(name);
// associate the DC with the cell in the map
myPMManagerDC->addCellDCPair(std::ComponentDCPair(myComponent, this));
myProp = NULL;
}
// -------------------- destructor --------------------
CellDC::~CellDC() {
delete myProp;
myProp = NULL;
}
// -------------------- getPropertyObject --------------------
QObject * CellDC::getPropertyObject() {
if (!myProp) {
myProp = new CellDCProperties(this);
}
return myProp;
}
// -------------------- setSelected -------------------
void CellDC::setSelected(const bool selected, const bool recursive) {
// if selected for the 1st time: create geometry
if (!myGeometry) {
// create it
initRepresentation();
}
if (selected) {
// add it in the InteractiveViewer
setVisibility(InteractiveViewer::get3DViewer(), true);
// add surfacic representation
RenderingModes rm = getRenderingModes();
camitk::Component::setRenderingModes(rm | InterfaceGeometry::Surface);
}
else {
// remove the representation
setVisibility(InteractiveViewer::get3DViewer(), false);
}
camitk::Component::setSelected(selected,false);
}
// -------------------- initRepresentation -------------------
void CellDC::initRepresentation() {
// create the vector and map
updateAtoms();
// create the points for the cell
vtkSmartPointer<vtkPoints> thePoints = vtkSmartPointer<vtkPoints>::New();
vtkIdType *vtkPointIndex = new vtkIdType[childrenComponent.size()];
// NOTE : the index of each atom in the vtk structure is in fact
// its order number in the atoms structure (not its actual index)
double pos[3];
unsigned int i = 0;
foreach(camitk::Component *dc, childrenComponent) {
dynamic_cast<AtomDC *>(dc)->getAtom()->getPosition(pos);
thePoints->InsertPoint(i, pos[0], pos[1], pos[2]);
vtkPointIndex[i] = i;
i++;
}
// instanciate a new one
if (dynamic_cast<Cell *>(myComponent)->getType() != StructureProperties::POLY_LINE) {
vtkSmartPointer<vtkUnstructuredGrid> uGrid = vtkSmartPointer<vtkUnstructuredGrid>::New();
uGrid->Allocate(1);
int cellType;
switch (dynamic_cast<Cell *>(myComponent)->getType()){
case StructureProperties::TETRAHEDRON:
cellType = VTK_TETRA;
break;
case StructureProperties::HEXAHEDRON:
cellType = VTK_HEXAHEDRON;
break;
case StructureProperties::WEDGE:
cellType = VTK_WEDGE;
break;
case StructureProperties::PYRAMID:
cellType = VTK_PYRAMID;
break;
case StructureProperties::POLY_VERTEX:
cellType = VTK_POLY_VERTEX;
break;
case StructureProperties::TRIANGLE:
cellType = VTK_TRIANGLE;
break;
case StructureProperties::QUAD:
cellType = VTK_QUAD;
break;
case StructureProperties::LINE:
cellType = VTK_LINE;
break;
default:
cellType = VTK_VERTEX;
break;
}
uGrid->InsertNextCell(cellType, (vtkIdType) childrenComponent.size(), vtkPointIndex);
uGrid->SetPoints(thePoints);
uGrid->Update();
delete [] vtkPointIndex;
// create the new geometry
myGeometry = new Geometry(this->getName(), uGrid, myPMManagerDC->toDCRenderingMode(getSC()->getMode()));
}
else {
// polyline -> tubes (and for tubes it has to be a polydata not a ugrid
vtkSmartPointer<vtkPolyData> polyD = vtkSmartPointer<vtkPolyData>::New();
polyD->Allocate(1);
polyD->InsertNextCell(VTK_POLY_LINE, (vtkIdType) childrenComponent.size(), vtkPointIndex);
polyD->SetPoints(thePoints);
polyD->Update();
delete [] vtkPointIndex;
// create the new geometry
myGeometry = new Geometry(this->getName(), polyD, myPMManagerDC->toDCRenderingMode(getSC()->getMode()));
}
// if the cell has no specically defined color, ask the parent structural component
StructuralComponentProperties::Color oColor;
oColor = getSC()->getStructuralComponentPropertiesColor();
double oRGBA[4];
// check the first sc color (if exist)
if (oColor == StructuralComponentProperties::DEFAULT && myCell->getNumberOfStructuralComponents() > 0) {
// take the first structural component that I am composing
StructuralComponent *sc = myCell->getStructuralComponent(0);
oColor = sc->getStructuralComponentPropertiesColor();
// if the sc has a special color, use it as well
if (oColor != StructuralComponentProperties::DEFAULT) {
// get the color...
sc->getColor(&oRGBA[0], &oRGBA[1], &oRGBA[2], &oRGBA[3]);
//... but not the alpha channel (by default = 255)
//oRGBA[3] = 255;
myGeometry->setActorColor(InterfaceGeometry::Surface, oRGBA);
// if the sc is no specifically defined color, do nothing (use the default Geometry color)
}
}
else
// if the cell has a specifically defined color, use it
myGeometry->setActorColor(InterfaceGeometry::Surface, getSC()->getColor());
}
// -------------------- setName --------------------
void CellDC::setName(const QString & n) {
Cell * myCell = dynamic_cast<Cell *>(myComponent);
dynamic_cast<Structure *>(myCell)->setName(n.toStdString());
camitk::Component::setName(n);
}
//------------------------ getPixmap ---------------------
#include "cell_20x20.xpm"
QPixmap * CellDC::myPixmap = NULL;
QPixmap CellDC::getIcon() {
if (!myPixmap) {
myPixmap = new QPixmap(cell_20x20);
}
return (*myPixmap);
}
//-------------------- createPointData -------------------
void CellDC::createPointData() {
if (!pointData) {
// create a new vtkDataArray
pointData = vtkSmartPointer<vtkDoubleArray>::New();
pointData->SetNumberOfTuples(childrenComponent.size());
setPointData(pointData);
// give the atom DCs the address of the corresponding point data
int i = 0;
foreach(camitk::Component *dc, childrenComponent) {
dynamic_cast<AtomDC *>(dc)->addPointData(this, pointData->GetPointer(i));
i++;
}
}
}
//-------------------- destroyPointData -------------------
void CellDC::destroyPointData() {
if (pointData) {
// delete the pointData
pointData = NULL;
setPointData(NULL);
// clear the AtomDC's pointers
foreach(camitk::Component *dc, childrenComponent) {
dynamic_cast<AtomDC *>(dc)->clearPointData();
}
}
}
|