37 #include <vtkVolume.h>
38 #include <vtkAssemblyNode.h>
39 #include <vtkAssemblyPath.h>
40 #include <vtkCellArray.h>
41 #include <vtkCellData.h>
42 #include <vtkCellPicker.h>
43 #include <vtkDoubleArray.h>
44 #include <vtkCommand.h>
45 #include <vtkMatrix4x4.h>
46 #include <vtkPoints.h>
47 #include <vtkPointData.h>
48 #include <vtkPolyData.h>
49 #include <vtkDataSet.h>
50 #include <vtkPolyDataMapper.h>
51 #include <vtkDataSetMapper.h>
53 #include <vtkProp3DCollection.h>
54 #include <vtkProperty.h>
55 #include <vtkRenderer.h>
56 #include <vtkRendererCollection.h>
57 #include <vtkRenderWindow.h>
58 #include <vtkRenderWindowInteractor.h>
59 #include <vtkSmartPointer.h>
60 #include <vtkTimerLog.h>
61 #include <vtkUnstructuredGrid.h>
63 #include <vtkShader.h>
65 #include <vtkShaderProgram.h>
66 #include <vtkOpenGLProperty.h>
76 virtual void Execute(vtkObject *caller,
unsigned long event,
void *)
79 if(event == vtkCommand::InteractionEvent) {
80 if (dynamic_cast <axlAbstractCurveBSpline *>(
observerData)) {
82 actorCurveBSpline->pointsUpdate();
84 else if (dynamic_cast <axlAbstractSurfaceBSpline *>(
observerData)) {
86 actorSurfaceBSpline->pointsUpdate();
89 else if (dynamic_cast <axlAbstractVolumeBSpline *>(
observerData)) {
91 actorVolumeBSpline->pointsUpdate();
93 else if (dynamic_cast <axlShapeBSpline *>(
observerData)) {
95 actorShapeBSpline->pointsUpdate();
98 if (dynamic_cast<axlAbstractData *>(
observerData)->fields().count() != 0) {
105 if (event == vtkCommand::LeftButtonPressEvent && interactor->GetShiftKey()) {
114 if(event == vtkCommand::RightButtonPressEvent && interactor->GetShiftKey()) {
116 if (interactor->GetControlKey())
125 if(event == vtkCommand::KeyPressEvent) {
127 QString modifier(interactor->GetKeySym());
152 vtkSmartPointer<vtkAssemblyPath> path;
154 vtkSmartPointer<vtkRenderWindow> renderWindow = interactor->GetRenderWindow();
155 vtkSmartPointer<vtkRendererCollection> rendererCollection = renderWindow->GetRenderers();
156 vtkSmartPointer<vtkRenderer> render = rendererCollection->GetFirstRenderer();
157 int X = interactor->GetEventPosition()[0];
158 int Y = interactor->GetEventPosition()[1];
160 if (!render || !render->IsInViewport(X, Y))
162 qDebug()<<
" No renderer or bad cursor coordonates in axlActor";
176 if (!pathNull && path != NULL)
179 vtkCollectionSimpleIterator listPropIterator;
180 path->InitTraversal(listPropIterator);
181 vtkSmartPointer<vtkAssemblyNode> node;
204 else if(pathNull && path==NULL)
226 class axlActorPrivate
229 vtkSmartPointer<vtkPoints> points;
230 vtkSmartPointer<vtkPolyData> polyData;
231 vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid;
232 vtkSmartPointer<vtkCellArray> cellArray;
233 vtkSmartPointer<vtkDoubleArray> normals;
234 vtkSmartPointer<vtkActor> actor;
235 vtkSmartPointer<vtkPolyDataMapper> mapper;
237 vtkSmartPointer<vtkVolume> actor3D;
238 vtkSmartPointer<vtkDataSetMapper> mapper3D;
239 vtkRenderWindowInteractor *interactor;
240 vtkSmartPointer<vtkCellPicker> CpCursorPicker;
246 QString active_scalars;
251 return (
bool)(this->GetVisibility());
257 d->interactor =
static_cast<vtkRenderWindowInteractor *
>(interactor);
259 d->interactor = NULL;
266 return d->interactor;
272 return d->observer->getData();
292 d->normals = normals;
302 d->polyData = polyData;
314 d->cellArray = cellArray;
352 d->mapper3D = mapper;
358 return d->CpCursorPicker;
363 d->CpCursorPicker = cellPicker;
373 d->observer = observer;
378 return d->unstructuredGrid;
383 d->unstructuredGrid = unstructuredGrid;
390 d->observer->observerDataAssembly =
this;
392 d->observer->observerData_points = this->
getPoints();
394 d->observer->observerData_polyData = this->
getPolyData();
397 d->observer->observerData_actor = this->
getActor();
399 d->interactor->AddObserver(vtkCommand::LeftButtonPressEvent, d->observer);
400 d->interactor->AddObserver(vtkCommand::RightButtonPressEvent, d->observer);
401 d->interactor->AddObserver(vtkCommand::InteractionEvent, d->observer);
402 d->interactor->AddObserver(vtkCommand::KeyPressEvent, d->observer);
408 d->interactor->RemoveObservers(vtkCommand::LeftButtonPressEvent, d->observer);
409 d->interactor->RemoveObservers(vtkCommand::RightButtonPressEvent, d->observer);
410 d->interactor->RemoveObservers(vtkCommand::InteractionEvent, d->observer);
411 d->interactor->RemoveObservers(vtkCommand::KeyPressEvent, d->observer);
413 d->observer->observerDataAssembly = NULL;
414 d->observer->observerDataPicker = NULL;
415 d->observer->observerData_points = NULL;
416 d->observer->observerData_polyData = NULL;
417 d->observer->observerData_UnstructuredGrid = NULL;
418 d->observer->observerData_actor = NULL;
419 d->observer->Delete();
426 d->observer->setData(data);
443 qDebug() <<
"No tet actor computed for this axlActor";
448 if (!this->GetParts()->IsItemPresent(this->
getActor())) {
449 this->VisibilityOn();
454 if (this->GetParts()->IsItemPresent(this->
getActor())!=0) {
455 this->VisibilityOff();
466 double opa =
data->opacity();
467 d->actor->GetProperty()->SetOpacity(opa);
476 if (dynamic_cast<axlAbstractData *>(this->
data())) {
478 d->actor->SetScale(size);
484 d->actor->GetProperty()->SetInterpolation(interpolation);
487 data->setInterpolation(interpolation);
497 vtkProperty *prop = this->
getActor()->GetProperty();
498 QColor color =
data->color();
501 prop->SetColor(color.redF(), color.greenF(), color.blueF());
505 qreal *h =
new qreal(0.0);
506 qreal *s =
new qreal(0.0);
507 qreal *l =
new qreal(0.0);
508 color.getHslF(h, s, l);
509 color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
510 prop->SetColor(color.redF(), color.greenF(), color.blueF());
520 vtkProperty *prop = this->
getActor()->GetProperty();
522 if (QFile::exists(vsfile)) {
523 QFileInfo file_info = QFileInfo(vsfile);
525 QString shader_vertex_extension =
".vs";
526 QString shader_fragment_extension =
".fs";
528 QString vertex_shader_source = dtkReadFile(file_info.path() +
"/" +
529 file_info.completeBaseName() +
530 shader_vertex_extension);
532 QString fragment_shader_source = dtkReadFile(file_info.path() +
"/" +
533 file_info.completeBaseName() +
534 shader_fragment_extension);
540 prop->vtkProperty::ShadingOff();
547 QString fragment_shader_source)
549 vtkProperty *prop = this->
getActor()->GetProperty();
551 if ((vertex_shader_source !=
"") && (fragment_shader_source !=
"")) {
553 vtkSmartPointer<vtkShaderProgram> program = vtkSmartPointer<vtkShaderProgram>::New();
557 vtkSmartPointer<vtkShader> fragment_shader = vtkSmartPointer<vtkShader>::New();
560 fragment_shader->SetType(vtkShader::Type::Fragment);
562 fragment_shader->SetSource(fragment_shader_source.toStdString().c_str());
566 vtkSmartPointer<vtkShader> vertex_shader = vtkSmartPointer<vtkShader>::New();
569 vertex_shader->SetType(vtkShader::Type::Vertex);
571 vertex_shader->SetSource(vertex_shader_source.toStdString().c_str());
575 program->SetVertexShader(vertex_shader);
577 program->SetFragmentShader(fragment_shader);
580 vtkSmartPointer<vtkOpenGLProperty> openGLproperty =
static_cast<vtkOpenGLProperty*
>(prop);
584 prop->vtkProperty::ShadingOn();
587 prop->vtkProperty::ShadingOff();
598 this->VisibilityOff();
604 this->VisibilityOn();
616 this->RemoveAllObservers();
618 this->
getActor()->RemoveAllObservers();
621 actorComposite->removeActorReference(
this);
737 for(
int i = 0; i < d->polyData->GetPointData()->GetNumberOfArrays(); i++)
738 fields << QString(d->polyData->GetPointData()->GetArray(i)->GetName());
740 for(
int i = 0; i < d->polyData->GetCellData()->GetNumberOfArrays(); i++)
741 fields << QString(d->polyData->GetCellData()->GetArray(i)->GetName());
743 for(
int i = 0; i < d->polyData->GetFieldData()->GetNumberOfArrays(); i++)
744 fields << QString(d->polyData->GetFieldData()->GetArray(i)->GetName());
746 if(d->unstructuredGrid){
747 for(
int i = 0; i < d->unstructuredGrid->GetPointData()->GetNumberOfArrays(); i++)
748 fields << QString(d->unstructuredGrid->GetPointData()->GetArray(i)->GetName());
750 for(
int i = 0; i < d->unstructuredGrid->GetCellData()->GetNumberOfArrays(); i++)
751 fields << QString(d->unstructuredGrid->GetCellData()->GetArray(i)->GetName());
753 for(
int i = 0; i < d->unstructuredGrid->GetFieldData()->GetNumberOfArrays(); i++)
754 fields << QString(d->unstructuredGrid->GetFieldData()->GetArray(i)->GetName());
763 double matrix[16]; this->GetMatrix(matrix);
764 qDebug()<<
" Matrix of the assembly " <<
this;
765 for(
int i = 0 ; i < 4 ; i++)
766 qDebug()<<matrix[4 * i + 0]<<matrix[4 * i + 1]<<matrix[4 * i + 2]<<matrix[4 * i + 3];
774 d->CpCursorPicker = vtkSmartPointer<vtkCellPicker>::New();
775 d->CpCursorPicker->SetTolerance(0.001);
virtual void Execute(vtkObject *caller, unsigned long event, void *)
vtkSmartPointer< vtkCellArray > getCellArray(void)
void setDataSetMapper(vtkSmartPointer< vtkDataSetMapper > mapper)
vtkSmartPointer< vtkDoubleArray > getNormals(void)
void setUnstructuredGrid(vtkSmartPointer< vtkUnstructuredGrid > unstructuredGrid)
virtual void setDisplay(bool display)
void setNormals(vtkSmartPointer< vtkDoubleArray > normals)
dtkAbstractData * getObserverData(void)
vtkSmartPointer< vtkPolyData > getPolyData(void)
virtual void setShaderFromString(QString vertex_shader_source, QString fragment_shader_source)
vtkSmartPointer< vtkPolyData > observerData_polyData
virtual void setState(int state)
virtual dtkAbstractData * getData(void)
virtual void setColor(double red, double green, double blue)
virtual void pickAndSetMode(int state, bool pathNull)
void setCellArray(vtkSmartPointer< vtkCellArray > cellArray)
static axlActorControlPolygonObserver * New(void)
virtual int getState(void)
virtual void update(void)
virtual void setInteractor(void *interactor)
vtkSmartPointer< vtkCellPicker > getCellPicker()
vtkSmartPointer< vtkCellPicker > observerDataPicker
void deleteObserver(void)
virtual void setData(dtkAbstractData *data)
void setCellPicker(vtkSmartPointer< vtkCellPicker > cellPicker)
virtual void setMode(int state)
void setObserver(axlActorControlPolygonObserver *observer)
virtual bool isVisible(void)
vtkSmartPointer< vtkPoints > getPoints(void)
void drawAssymblyMatrix(void)
virtual void setSize(double size)
vtkSmartPointer< vtkActor > observerData_actor
virtual void setInterpolation(int interpolation)
virtual void setShader(QString vsfile)
virtual void onRemoved(void)
void setvtkVolume(vtkSmartPointer< vtkVolume > actor)
virtual axlAbstractActor * parent(void)
virtual void setOpacity(double opacity)
void setPolyData(vtkSmartPointer< vtkPolyData > polyData)
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
vtkSmartPointer< vtkVolume > getvtkVolume(void)
virtual dtkAbstractData * data(void)=0
vtkSmartPointer< vtkUnstructuredGrid > getUnstructuredGrid(void)
vtkSmartPointer< vtkDataSetMapper > getDataSetMapper(void)
void setActor(vtkSmartPointer< vtkActor > actor)
vtkSmartPointer< vtkActor > getActor(void)
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
dtkAbstractData * observerData
void setObserverData(dtkAbstractData *data)
vtkSmartPointer< vtkUnstructuredGrid > observerData_UnstructuredGrid
axlActorControlPolygonObserver * getObserver(void)
virtual vtkRenderWindowInteractor * getInteractor(void)
vtkSmartPointer< vtkPoints > observerData_points
axlActor * observerDataAssembly
Class axlAbstractData defines an API for all type of axel data.
void setPoints(vtkSmartPointer< vtkPoints > points)
Class axlMesh defines a piecewise-linear 3D object.