36 #include <vtkRenderer.h> 38 #include <vtkPolyDataMapper.h> 39 #include <vtkProperty.h> 40 #include <vtkSectorSource.h> 42 #include "vtkMatrix4x4.h" 43 #include "vtkLinearExtrusionFilter.h" 44 #include "vtkPolyDataNormals.h" 52 mDirection = Vector3D::UnitZ();
56 mColor = QColor(Qt::blue);
58 mOutlineColor = QColor(Qt::magenta);
74 mOutlineWidth = width;
82 mOutlineColor = color;
96 mDirection = direction;
109 this->removeActors();
110 mRenderer = renderer;
114 void GraphicalDisk::addActors()
116 if (mRenderer && mCircleActor && mOutlineActor)
118 mRenderer->AddActor(mCircleActor);
119 mRenderer->AddActor(mOutlineActor);
123 void GraphicalDisk::removeActors()
125 if (mRenderer && mCircleActor && mOutlineActor)
127 mRenderer->RemoveActor(mCircleActor);
128 mRenderer->RemoveActor(mOutlineActor);
139 this->createActors();
149 double innerRadius = std::max(0.0, mRadius*(1.0 - mOutlineWidth));
150 mCircleSource->SetOuterRadius(innerRadius);
151 mOutlineSource->SetInnerRadius(innerRadius);
152 mOutlineSource->SetOuterRadius(mRadius);
154 mCircleExtruder->SetScaleFactor(mHeight);
155 mOutlineExtruder->SetScaleFactor(mHeight);
157 mCircleActor->SetVisibility(mFillVisible);
159 this->updateOrientation();
162 void GraphicalDisk::createActors()
169 mCircleSource = vtkSectorSourcePtr::New();
170 mCircleSource->SetOuterRadius(mRadius);
171 mCircleSource->SetInnerRadius(0);
172 mCircleSource->SetStartAngle(0);
173 mCircleSource->SetEndAngle(360);
174 mCircleSource->SetCircumferentialResolution(resolution);
176 mCircleExtruder = vtkLinearExtrusionFilterPtr::New();
177 mCircleExtruder->SetInputConnection(mCircleSource->GetOutputPort());
178 mCircleExtruder->SetScaleFactor(mHeight);
179 mCircleExtruder->SetExtrusionTypeToVectorExtrusion();
180 mCircleExtruder->SetVector(0,0,1);
183 mapper->SetInputConnection(mCircleExtruder->GetOutputPort());
184 mapper->ScalarVisibilityOff();
185 mCircleActor = vtkActorPtr::New();
186 mCircleActor->SetMapper(mapper);
187 mCircleActor->GetProperty()->SetLighting(mUseLighting);
189 mOutlineSource = vtkSectorSourcePtr::New();
190 mOutlineSource->SetOuterRadius(mRadius);
191 mOutlineSource->SetInnerRadius(0);
192 mOutlineSource->SetStartAngle(0);
193 mOutlineSource->SetEndAngle(360);
194 mOutlineSource->SetCircumferentialResolution(resolution);
196 mOutlineExtruder = vtkLinearExtrusionFilterPtr::New();
197 mOutlineExtruder->SetInputConnection(mOutlineSource->GetOutputPort());
198 mOutlineExtruder->SetScaleFactor(mHeight);
199 mOutlineExtruder->SetExtrusionTypeToVectorExtrusion();
200 mOutlineExtruder->SetVector(0,0,1);
203 normals->SetInputConnection(mOutlineExtruder->GetOutputPort());
206 outlineMapper->SetInputConnection(normals->GetOutputPort());
207 outlineMapper->ScalarVisibilityOff();
208 mOutlineActor = vtkActorPtr::New();
209 mOutlineActor->SetMapper(outlineMapper);
210 mOutlineActor->GetProperty()->SetLighting(mUseLighting);
214 void GraphicalDisk::updateOrientation()
220 bool directionAlongYAxis =
similar(
dot(from, mDirection.normal()), 1.0);
222 if (directionAlongYAxis)
224 M = Transform3D::Identity();
240 mCircleActor->SetUserMatrix(M.getVtkMatrix());
241 mOutlineActor->SetUserMatrix(M.getVtkMatrix());
250 double r = this->getRadiusOfCircleSlicedFromSphere(sphereRadius, sliceHeight);
254 double GraphicalDisk::getRadiusOfCircleSlicedFromSphere(
double sphereRadius,
double sliceHeight)
const 258 if (std::abs(sliceHeight) > sphereRadius)
264 retval = sphereRadius*cos(asin(sliceHeight/sphereRadius));
void setRadius(double radius)
Vector3D getColorAsVector3D(QColor color)
void setColor(QColor color)
vtkSmartPointer< class vtkPolyDataMapper > vtkPolyDataMapperPtr
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
void setLighting(bool on)
void setPosition(Vector3D pos)
void setRenderer(vtkRendererPtr renderer=vtkRendererPtr())
Vector3D cross(const Vector3D &a, const Vector3D &b)
compute cross product of a and b.
void setOutlineWidth(double width)
void setHeight(double height)
Transform3D createTransformIJC(const Vector3D &ivec, const Vector3D &jvec, const Vector3D ¢er)
vtkSmartPointer< class vtkRenderer > vtkRendererPtr
vtkSmartPointer< class vtkPolyDataNormals > vtkPolyDataNormalsPtr
void setOutlineColor(QColor color)
void setRadiusBySlicingSphere(double sphereRadius, double sliceHeight)
void setDirection(Vector3D direction)
Transform3D createTransformTranslate(const Vector3D &translation)
double dot(const Vector3D &a, const Vector3D &b)
compute inner product (or dot product) of a and b.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
bool similar(const CameraInfo &lhs, const CameraInfo &rhs, double tol)
void setFillVisible(bool val)
Namespace for all CustusX production code.