28 #include <QVTKOpenGLWidget.h> 
   31 #include <vtkAssemblyPath.h> 
   33 #include <vtkCommand.h> 
   34 #include <vtkGlyph3D.h> 
   35 #include <vtkInteractorStyleSwitch.h> 
   37 #include <vtkLightCollection.h> 
   38 #include <vtkParametricFunctionSource.h> 
   39 #include <vtkParametricTorus.h> 
   40 #include <vtkLineWidget.h> 
   41 #include <vtkObjectFactory.h> 
   42 #include <vtkPoints.h> 
   43 #include <vtkPointWidget.h> 
   44 #include <vtkPolyData.h> 
   45 #include <vtkPolyDataMapper.h> 
   46 #include <vtkProperty.h> 
   47 #include <vtkRenderer.h> 
   48 #include <vtkRendererCollection.h> 
   49 #include <vtkRenderWindow.h> 
   50 #include <vtkRenderWindowInteractor.h> 
   51 #include <vtkSmartPointer.h> 
   52 #include <vtkTransform.h> 
   61     virtual void Execute(vtkObject *caller, 
unsigned long event, 
void *) {
 
   64         if(event == vtkCommand::InteractionEvent) {
 
  107                 axlPoint AB(crossSectionPoint - center);
 
  108                 double normABH = (v.
x() * AB.
x() + v.
y() * AB.
y() + v.
z() * AB.
z());
 
  112                 if (newCrossSectionRadius > 0) {
 
  125                 double normABH = (u.x() * AB.
x() + u.y() * AB.
y() + u.z() * AB.
z());
 
  194 class axlActorTorusPrivate
 
  198     vtkParametricFunctionSource *torusSource;
 
  199     vtkPointWidget *ringRadiusPointWidget;
 
  200     vtkPointWidget *crosSectionRadiusPointWidget;
 
  201     vtkLineWidget *directionLineWidget;
 
  203     QVTKOpenGLWidget *widget;
 
  205     vtkParametricTorus* vtkTorus;
 
  208 #if (VTK_MAJOR_VERSION <= 5) 
  219     return d->torusSource;
 
  231         this->
setMapper(vtkSmartPointer<vtkPolyDataMapper>::New());
 
  232         this->
setActor(vtkSmartPointer<vtkActor>::New());
 
  234         d->torusSource = vtkParametricFunctionSource::New();
 
  236         d->vtkTorus = vtkParametricTorus::New();
 
  237         d->vtkTorus->SetRingRadius(d->torus->ringRadius());
 
  238         d->vtkTorus->SetCrossSectionRadius(d->torus->crossSectionRadius());
 
  239         d->torusSource->SetParametricFunction(d->vtkTorus);
 
  242 #if (VTK_MAJOR_VERSION <= 5) 
  243         this->
getMapper()->SetInput(d->torusSource->GetOutput());
 
  245         this->
getMapper()->SetInputData(d->torusSource->GetOutput());
 
  251         if(!d->torusObserver) {
 
  254             this->
getInteractor()->AddObserver(vtkCommand::InteractionEvent, d->torusObserver);
 
  255             this->
getInteractor()->AddObserver(vtkCommand::MouseMoveEvent, d->torusObserver);
 
  257             d->torusObserver->observerDataAssembly = 
this;
 
  259             d->torusObserver->observerData_torusSource = d->torusSource;
 
  260             d->torusObserver->observerData_torus = d->torus;
 
  261             d->torusObserver->vtkTorus = d->vtkTorus;
 
  265         QColor color = d->torus->color();
 
  266         this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
 
  268         QString shader = d->torus->shader();
 
  269         if(!shader.isEmpty())
 
  273         connect(d->torus, SIGNAL(modifiedGeometry()),
this, SLOT(
onUpdateGeometry()));
 
  274         connect(d->torus, SIGNAL(modifiedProperty()),
this, SLOT(
onUpdateProperty()));
 
  277         qDebug()<< 
"no axlTorus available";
 
  284     if (display && d->directionLineWidget) {
 
  288     if (!display && d->directionLineWidget) {
 
  294     if (!d->ringRadiusPointWidget || !d->crosSectionRadiusPointWidget || !d->directionLineWidget) {
 
  295         qDebug() << 
"No actor computed for this axlActorTorus.";
 
  300         d->ringRadiusPointWidget->SetEnabled(1);
 
  301         d->crosSectionRadiusPointWidget->SetEnabled(1);
 
  302         d->directionLineWidget->SetEnabled(1);
 
  306         d->ringRadiusPointWidget->SetEnabled(0);
 
  307         d->crosSectionRadiusPointWidget->SetEnabled(0);
 
  308         d->directionLineWidget->SetEnabled(0);
 
  316         if(!d->ringRadiusPointWidget || !d->crosSectionRadiusPointWidget || !d->directionLineWidget) {
 
  319             axlPoint center = *(d->torus->centerPoint());
 
  322             d->ringRadiusPointWidget = vtkPointWidget::New();
 
  323             d->ringRadiusPointWidget->SetInteractor(this->
getInteractor());
 
  324             d->ringRadiusPointWidget->SetProp3D(this->
getActor());
 
  325             d->ringRadiusPointWidget->PlaceWidget();
 
  326             d->ringRadiusPointWidget->AllOff();
 
  327             d->ringRadiusPointWidget->SetTranslationMode(1);
 
  330             axlPoint orientationX(this->
getActor()->GetMatrix()->GetElement(0,0), this->
getActor()->GetMatrix()->GetElement(1,0), this->
getActor()->GetMatrix()->GetElement(2,0));
 
  332             d->ringRadiusPointWidget->SetPosition((center + (orientationX * (d->torus->ringRadius() + d->torus->crossSectionRadius()))).coordinates());
 
  335             d->crosSectionRadiusPointWidget = vtkPointWidget::New();
 
  336             d->crosSectionRadiusPointWidget->SetInteractor(this->
getInteractor());
 
  337             d->crosSectionRadiusPointWidget->SetProp3D(this->
getActor());
 
  338             d->crosSectionRadiusPointWidget->PlaceWidget();
 
  339             d->crosSectionRadiusPointWidget->AllOff();
 
  340             d->crosSectionRadiusPointWidget->SetTranslationMode(1);
 
  343             axlPoint orientationY(this->
getActor()->GetMatrix()->GetElement(0,1), this->
getActor()->GetMatrix()->GetElement(1,1), this->
getActor()->GetMatrix()->GetElement(2,1));
 
  345             d->crosSectionRadiusPointWidget->SetPosition((center + (orientationY * (d->torus->ringRadius() - d->torus->crossSectionRadius()))).coordinates());
 
  348             d->directionLineWidget = vtkLineWidget::New();
 
  349             d->directionLineWidget->SetInteractor(this->
getInteractor());
 
  350             d->directionLineWidget->SetProp3D(this->
getActor());
 
  351             d->directionLineWidget->PlaceWidget();
 
  353             d->directionLineWidget->SetPoint1(d->torus->direction()->coordinates());
 
  354             d->directionLineWidget->SetPoint2(center.
coordinates());
 
  358         if(d->torusObserver) {
 
  359             d->ringRadiusPointWidget->AddObserver(vtkCommand::InteractionEvent, d->torusObserver);
 
  360             d->crosSectionRadiusPointWidget->AddObserver(vtkCommand::InteractionEvent, d->torusObserver);
 
  361             d->directionLineWidget->AddObserver(vtkCommand::InteractionEvent, d->torusObserver);
 
  363             d->torusObserver->ringRadiusPointWidget = d->ringRadiusPointWidget;
 
  364             d->torusObserver->crossSectionRadiusPointWidget = d->crosSectionRadiusPointWidget;
 
  365             d->torusObserver->directionLineWidget = d->directionLineWidget;
 
  369         d->ringRadiusPointWidget->SetEnabled(
true);
 
  370         d->crosSectionRadiusPointWidget->SetEnabled(
true);
 
  371         d->directionLineWidget->SetEnabled(
true);
 
  379             if(d->ringRadiusPointWidget) {
 
  380                 d->ringRadiusPointWidget->RemoveAllObservers();
 
  381                 d->ringRadiusPointWidget->SetEnabled(
false);
 
  382                 d->ringRadiusPointWidget->Delete(); 
 
  383                 d->ringRadiusPointWidget = NULL;
 
  386             if(d->crosSectionRadiusPointWidget) {
 
  387                 d->crosSectionRadiusPointWidget->RemoveAllObservers();
 
  388                 d->crosSectionRadiusPointWidget->SetEnabled(
false);
 
  389                 d->crosSectionRadiusPointWidget->Delete(); 
 
  390                 d->crosSectionRadiusPointWidget = NULL;
 
  393             if(d->directionLineWidget) {
 
  394                 d->directionLineWidget->RemoveAllObservers();
 
  395                 d->directionLineWidget->SetEnabled(
false);
 
  396                 d->directionLineWidget->Delete(); 
 
  397                 d->directionLineWidget = NULL;
 
  401     if (d->torusObserver){
 
  402         d->torusObserver->ringRadiusPointWidget = d->ringRadiusPointWidget;
 
  403         d->torusObserver->crossSectionRadiusPointWidget = d->crosSectionRadiusPointWidget;
 
  404         d->torusObserver->directionLineWidget = d->directionLineWidget;
 
  409     if(!d->ringRadiusPointWidget || !d->crosSectionRadiusPointWidget || !d->directionLineWidget) {
 
  410         qDebug() << 
"No actor computed for this axlActorBSpline.";
 
  414     return d->ringRadiusPointWidget->GetEnabled() && d->crosSectionRadiusPointWidget->GetEnabled() && d->directionLineWidget->GetEnabled();
 
  429             QColor color = 
data->color();
 
  430             this->
getActor()->GetProperty()->SetColor(color.redF(), color.greenF(), color.blueF());
 
  434     } 
else if(state == 1) {
 
  439         vtkProperty *prop = this->
getActor()->GetProperty();
 
  442             QColor color = 
data->color();
 
  443             qreal *h = 
new qreal(0.0);
 
  444             qreal *s = 
new qreal(0.0);
 
  445             qreal *l = 
new qreal(0.0);
 
  446             color.getHslF(h, s, l);
 
  447             color.setHslF(*h, *s, *l + (1.0 - *l) / 2.0);
 
  448             prop->SetColor(color.redF(), color.greenF(), color.blueF());
 
  454     } 
else if(state == 2) {
 
  458         vtkProperty *prop = this->
getActor()->GetProperty();
 
  460             QColor color = 
data->color();
 
  461             qreal *h = 
new qreal(0.0);
 
  462             qreal *s = 
new qreal(0.0);
 
  463             qreal *l = 
new qreal(0.0);
 
  464             color.getHslF(h, s, l);
 
  465             color.setHslF(*h, *s, *l + (1.0 - *l)/2.0);
 
  466             prop->SetColor(color.redF(), color.greenF(), color.blueF());
 
  485     if(d->torusObserver) {
 
  486         this->
getInteractor()->RemoveObservers(vtkCommand::InteractionEvent, d->torusObserver);
 
  487         this->
getInteractor()->RemoveObservers(vtkCommand::MouseMoveEvent, d->torusObserver);
 
  488         d->torusObserver->observerDataAssembly = NULL;
 
  490         d->torusObserver->observerData_torusSource = NULL;
 
  491         d->torusObserver->observerData_torus = NULL;
 
  492         d->torusObserver->axlInteractorStyle = NULL;
 
  493         d->torusObserver->Delete();
 
  494         d->torusObserver = NULL;
 
  501         d->torusSource->Delete();
 
  502         d->torusSource = NULL;
 
  511         d->vtkTorus->Delete();
 
  514     if(d->ringRadiusPointWidget && d->crosSectionRadiusPointWidget && d->directionLineWidget) {
 
  516         d->ringRadiusPointWidget = NULL;
 
  517         d->crosSectionRadiusPointWidget = NULL;
 
  518         d->directionLineWidget = NULL;
 
  522     this->RemoveAllObservers();
 
  524     this->
getActor()->RemoveAllObservers();
 
  527         actorComposite->removeActorReference(
this);
 
  531     d->vtkTorus->SetCrossSectionRadius(d->torus->crossSectionRadius());
 
  532     d->vtkTorus->SetRingRadius(d->torus->ringRadius());
 
  533     d->torusSource->Update();
 
  534     d->torusSource->Modified();
 
  536     axlPoint* center = d->torus->centerPoint();
 
  537     axlPoint* secondPoint = d->torus->direction();
 
  544     axlPoint n(direction->
y(), -direction->
x(), 0.0); 
 
  548     this->
getActor()->SetOrientation(0.0, 0.0, 0.0);
 
  549     this->
getActor()->RotateWXYZ(-acos(direction->
z()) * 180 / 3.14159, n.
x(), n.
y(), 0.0);
 
  557     if(d->ringRadiusPointWidget && d->crosSectionRadiusPointWidget) {
 
  559         axlPoint orientationX(this->
getActor()->GetMatrix()->GetElement(0,0), this->
getActor()->GetMatrix()->GetElement(1,0), this->
getActor()->GetMatrix()->GetElement(2,0));
 
  561         axlPoint orientationY(this->
getActor()->GetMatrix()->GetElement(0,1), this->
getActor()->GetMatrix()->GetElement(1,1), this->
getActor()->GetMatrix()->GetElement(2,1));
 
  563         d->ringRadiusPointWidget->SetPosition((*center + (orientationX * (d->torus->ringRadius() + d->torus->crossSectionRadius()))).coordinates());
 
  564         d->crosSectionRadiusPointWidget->SetPosition((*center + (orientationY * (d->torus->ringRadius() - d->torus->crossSectionRadius()))).coordinates());
 
  566         d->directionLineWidget->SetPoint1(secondPoint->
x(), secondPoint->
y(), secondPoint->
z());
 
  567         d->directionLineWidget->SetPoint2(center->
x(), center->
y(), center->
z());
 
  571     if(!d->torus->fields().isEmpty())
 
  572         d->torus->touchField();
 
  574     if(d->torus->updateView())
 
  580     d->ringRadiusPointWidget = NULL;
 
  581     d->crosSectionRadiusPointWidget = NULL;
 
  582     d->directionLineWidget = NULL;
 
  584     d->torusObserver = NULL;
 
  585     d->torusSource =NULL;
 
axlInteractorStyleSwitch * axlInteractorStyle
double crossSectionRadius
Class axlPoint defines 3D points. 
void setDisplay(bool display)
vtkLineWidget * directionLineWidget
virtual void setDisplay(bool display)
void setCenter(axlPoint *center)
double * coordinates(void) const 
Returns coordinates of this point. 
void stateChanged(dtkAbstractData *data, int mode)
vtkParametricTorus * vtkTorus
void setCrossSectionRadius(double crossSectionRadius)
virtual void setState(int state)
vtkCxxRevisionMacro(axlActorTorus,"$Revision: 0.0.1 $") vtkStandardNewMacro(axlActorTorus) dtkAbstractData *axlActorTorus
virtual void Execute(vtkObject *caller, unsigned long event, void *)
axlActorTorus * observerDataAssembly
virtual int getState(void)
dtkAbstractData * data(void)
axlTorus * observerData_torus
vtkParametricFunctionSource * torus(void)
static axlActorTorusObserver * New(void)
void setQVTKWidget(QVTKOpenGLWidget *widget)
virtual void setShader(QString vsfile)
void showTorusWidget(bool show)
axlAbstractActor * createAxlActorTorus(void)
void setTorusWidget(bool torusWidget)
virtual axlAbstractActor * parent(void)
virtual void setOpacity(double opacity)
virtual void setData(dtkAbstractData *torus1)
vtkPointWidget * ringRadiusPointWidget
void setMapper(vtkSmartPointer< vtkPolyDataMapper > mapper)
void setRingRadius(double ringRadius)
void setDirection(axlPoint *direction)
void setActor(vtkSmartPointer< vtkActor > actor)
vtkSmartPointer< vtkActor > getActor(void)
virtual void onUpdateProperty(void)
vtkSmartPointer< vtkPolyDataMapper > getMapper(void)
bool isShowTorusWidget(void)
void onModeChanged(int state)
vtkStandardNewMacro(axlActorCircleArc)
static double distance(const axlPoint &lhs, const axlPoint &rhs)
Returns the distance between lhs point and rhs point. 
virtual vtkRenderWindowInteractor * getInteractor(void)
Class axlAbstractData defines an API for all type of axel data. 
vtkParametricFunctionSource * observerData_torusSource
static axlActorTorus * New(void)
vtkPointWidget * crossSectionRadiusPointWidget