15 #include <vtkRenderer.h> 17 #include <vtkPolyDataMapper.h> 18 #include <vtkProperty.h> 19 #include <vtkSectorSource.h> 21 #include "vtkMatrix4x4.h" 22 #include "vtkLinearExtrusionFilter.h" 23 #include "vtkPolyDataNormals.h" 31 mDirection = Vector3D::UnitZ();
35 mColor = QColor(Qt::blue);
37 mOutlineColor = QColor(Qt::magenta);
53 mOutlineWidth = width;
61 mOutlineColor = color;
75 mDirection = direction;
93 void GraphicalDisk::addActors()
95 if (mRenderer && mCircleActor && mOutlineActor)
97 mRenderer->AddActor(mCircleActor);
98 mRenderer->AddActor(mOutlineActor);
102 void GraphicalDisk::removeActors()
104 if (mRenderer && mCircleActor && mOutlineActor)
106 mRenderer->RemoveActor(mCircleActor);
107 mRenderer->RemoveActor(mOutlineActor);
118 this->createActors();
128 double innerRadius = std::max(0.0, mRadius*(1.0 - mOutlineWidth));
129 mCircleSource->SetOuterRadius(innerRadius);
130 mOutlineSource->SetInnerRadius(innerRadius);
131 mOutlineSource->SetOuterRadius(mRadius);
133 mCircleExtruder->SetScaleFactor(mHeight);
134 mOutlineExtruder->SetScaleFactor(mHeight);
136 mCircleActor->SetVisibility(mFillVisible);
138 this->updateOrientation();
141 void GraphicalDisk::createActors()
148 mCircleSource = vtkSectorSourcePtr::New();
149 mCircleSource->SetOuterRadius(mRadius);
150 mCircleSource->SetInnerRadius(0);
151 mCircleSource->SetStartAngle(0);
152 mCircleSource->SetEndAngle(360);
153 mCircleSource->SetCircumferentialResolution(resolution);
155 mCircleExtruder = vtkLinearExtrusionFilterPtr::New();
156 mCircleExtruder->SetInputConnection(mCircleSource->GetOutputPort());
157 mCircleExtruder->SetScaleFactor(mHeight);
158 mCircleExtruder->SetExtrusionTypeToVectorExtrusion();
159 mCircleExtruder->SetVector(0,0,1);
162 mapper->SetInputConnection(mCircleExtruder->GetOutputPort());
163 mapper->ScalarVisibilityOff();
164 mCircleActor = vtkActorPtr::New();
165 mCircleActor->SetMapper(mapper);
166 mCircleActor->GetProperty()->SetLighting(mUseLighting);
168 mOutlineSource = vtkSectorSourcePtr::New();
169 mOutlineSource->SetOuterRadius(mRadius);
170 mOutlineSource->SetInnerRadius(0);
171 mOutlineSource->SetStartAngle(0);
172 mOutlineSource->SetEndAngle(360);
173 mOutlineSource->SetCircumferentialResolution(resolution);
175 mOutlineExtruder = vtkLinearExtrusionFilterPtr::New();
176 mOutlineExtruder->SetInputConnection(mOutlineSource->GetOutputPort());
177 mOutlineExtruder->SetScaleFactor(mHeight);
178 mOutlineExtruder->SetExtrusionTypeToVectorExtrusion();
179 mOutlineExtruder->SetVector(0,0,1);
182 normals->SetInputConnection(mOutlineExtruder->GetOutputPort());
185 outlineMapper->SetInputConnection(normals->GetOutputPort());
186 outlineMapper->ScalarVisibilityOff();
187 mOutlineActor = vtkActorPtr::New();
188 mOutlineActor->SetMapper(outlineMapper);
189 mOutlineActor->GetProperty()->SetLighting(mUseLighting);
193 void GraphicalDisk::updateOrientation()
199 bool directionAlongYAxis =
similar(
dot(from, mDirection.normal()), 1.0);
201 if (directionAlongYAxis)
203 M = Transform3D::Identity();
219 mCircleActor->SetUserMatrix(M.getVtkMatrix());
220 mOutlineActor->SetUserMatrix(M.getVtkMatrix());
229 double r = this->getRadiusOfCircleSlicedFromSphere(sphereRadius, sliceHeight);
233 double GraphicalDisk::getRadiusOfCircleSlicedFromSphere(
double sphereRadius,
double sliceHeight)
const 237 if (std::abs(sliceHeight) > sphereRadius)
243 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.