------------------------------------------------------------------------------
| 141 | |
| 142 | //------------------------------------------------------------------------------ |
| 143 | void vtk3DCursorRepresentation::WidgetInteraction(double newEventPos[2]) |
| 144 | { |
| 145 | if (!this->Renderer) |
| 146 | { |
| 147 | return; |
| 148 | } |
| 149 | |
| 150 | vtkCollectionSimpleIterator cookie; |
| 151 | vtkActorCollection* actorcol = this->Renderer->GetActors(); |
| 152 | vtkActor* actor; |
| 153 | std::map<vtkPolyDataMapper*, std::string> pointArrayNames; |
| 154 | std::map<vtkPolyDataMapper*, std::string> cellArrayNames; |
| 155 | |
| 156 | // Iterate through mappers to disable the potential use of point/cell data |
| 157 | // arrays for selection and enforce the use of cell IDs. |
| 158 | // This is needed in order to prevent a mismatch between the value retrieved |
| 159 | // with hardware picking and the ID of the point/cell we want to extract before |
| 160 | // computing the ray intersection (see vtkHardwarePicker). |
| 161 | // This typically happen in a ParaView context, where vtkOriginalPoint/CellIds |
| 162 | // is generated by the vtkPVGeometryFilter of the representation and used for |
| 163 | // the hardware selection by vtkPolyDataMapper. |
| 164 | for (actorcol->InitTraversal(cookie); (actor = actorcol->GetNextActor(cookie));) |
| 165 | { |
| 166 | // the mapper can be a composite polydata mapper or a single OpenGL polydata mapper. |
| 167 | if (auto cpdm = vtkCompositePolyDataMapper::SafeDownCast(actor->GetMapper())) |
| 168 | { |
| 169 | if (cpdm->GetPointIdArrayName()) |
| 170 | { |
| 171 | pointArrayNames.emplace(cpdm, cpdm->GetPointIdArrayName()); |
| 172 | cpdm->SetPointIdArrayName(nullptr); |
| 173 | } |
| 174 | if (cpdm->GetCellIdArrayName()) |
| 175 | { |
| 176 | cellArrayNames.emplace(cpdm, cpdm->GetCellIdArrayName()); |
| 177 | cpdm->SetCellIdArrayName(nullptr); |
| 178 | } |
| 179 | } |
| 180 | else if (auto glMapper = vtkPolyDataMapper::SafeDownCast(actor->GetMapper())) |
| 181 | { |
| 182 | if (glMapper->GetPointIdArrayName()) |
| 183 | { |
| 184 | pointArrayNames.emplace(glMapper, glMapper->GetPointIdArrayName()); |
| 185 | glMapper->SetPointIdArrayName(nullptr); |
| 186 | } |
| 187 | if (glMapper->GetCellIdArrayName()) |
| 188 | { |
| 189 | cellArrayNames.emplace(glMapper, glMapper->GetCellIdArrayName()); |
| 190 | glMapper->SetCellIdArrayName(nullptr); |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | this->Internals->Picker->Pick(newEventPos[0], newEventPos[1], 0.0, this->Renderer); |
| 196 | |
| 197 | // Restore the original point and cell data arrays after picking |
| 198 | for (auto item = pointArrayNames.begin(); item != pointArrayNames.end(); item++) |
| 199 | { |
| 200 | if (auto cpdm = vtkCompositePolyDataMapper::SafeDownCast(item->first)) |
nothing calls this directly
no test coverage detected