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));