| 1156 | } |
| 1157 | |
| 1158 | void vtkSplineWidget::SetNumberOfHandles(int npts) |
| 1159 | { |
| 1160 | if (this->NumberOfHandles == npts) |
| 1161 | { |
| 1162 | return; |
| 1163 | } |
| 1164 | if (npts < 2) |
| 1165 | { |
| 1166 | vtkGenericWarningMacro(<< "vtkSplineWidget: minimum of 2 points required."); |
| 1167 | return; |
| 1168 | } |
| 1169 | |
| 1170 | double radius = this->HandleGeometry[0]->GetRadius(); |
| 1171 | this->Initialize(); |
| 1172 | |
| 1173 | this->NumberOfHandles = npts; |
| 1174 | |
| 1175 | // Create the handles |
| 1176 | this->Handle = new vtkActor*[this->NumberOfHandles]; |
| 1177 | this->HandleGeometry = new vtkSphereSource*[this->NumberOfHandles]; |
| 1178 | |
| 1179 | int i; |
| 1180 | double pt[3]; |
| 1181 | double u[3]; |
| 1182 | for (i = 0; i < this->NumberOfHandles; ++i) |
| 1183 | { |
| 1184 | this->HandleGeometry[i] = vtkSphereSource::New(); |
| 1185 | this->HandleGeometry[i]->SetThetaResolution(16); |
| 1186 | this->HandleGeometry[i]->SetPhiResolution(8); |
| 1187 | vtkPolyDataMapper* handleMapper = vtkPolyDataMapper::New(); |
| 1188 | handleMapper->SetInputConnection(this->HandleGeometry[i]->GetOutputPort()); |
| 1189 | this->Handle[i] = vtkActor::New(); |
| 1190 | this->Handle[i]->SetMapper(handleMapper); |
| 1191 | handleMapper->Delete(); |
| 1192 | this->Handle[i]->SetProperty(this->HandleProperty); |
| 1193 | u[0] = i / (this->NumberOfHandles - 1.0); |
| 1194 | this->ParametricSpline->Evaluate(u, pt, nullptr); |
| 1195 | this->HandleGeometry[i]->SetCenter(pt); |
| 1196 | this->HandleGeometry[i]->SetRadius(radius); |
| 1197 | this->HandlePicker->AddPickList(this->Handle[i]); |
| 1198 | } |
| 1199 | |
| 1200 | this->BuildRepresentation(); |
| 1201 | |
| 1202 | if (this->Interactor) |
| 1203 | { |
| 1204 | if (!this->CurrentRenderer) |
| 1205 | { |
| 1206 | this->SetCurrentRenderer(this->Interactor->FindPokedRenderer( |
| 1207 | this->Interactor->GetLastEventPosition()[0], this->Interactor->GetLastEventPosition()[1])); |
| 1208 | } |
| 1209 | if (this->CurrentRenderer != nullptr) |
| 1210 | { |
| 1211 | for (i = 0; i < this->NumberOfHandles; ++i) |
| 1212 | { |
| 1213 | this->CurrentRenderer->AddViewProp(this->Handle[i]); |
| 1214 | } |
| 1215 | this->SizeHandles(); |