Changeset 3131 for trunk/packages
- Timestamp:
- Aug 2, 2012, 1:58:53 PM (12 years ago)
- Location:
- trunk/packages/vizservers/vtkvis
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/vtkvis/RpMolecule.cpp
r3112 r3131 6 6 */ 7 7 8 #include <cstdio> 8 9 #include <cassert> 9 10 … … 11 12 #include <vtkPointData.h> 12 13 #include <vtkFloatArray.h> 14 #include <vtkStringArray.h> 13 15 #include <vtkPolyData.h> 14 16 #include <vtkPolyDataMapper.h> … … 18 20 #include <vtkSphereSource.h> 19 21 #include <vtkGlyph3D.h> 22 #include <vtkPointSetToLabelHierarchy.h> 23 #include <vtkLabelPlacementMapper.h> 24 #include <vtkTextProperty.h> 20 25 21 26 #include "RpMolecule.h" … … 29 34 _radiusScale(0.3), 30 35 _atomScaling(VAN_DER_WAALS_RADIUS), 31 _colorMap(NULL) 36 _colorMap(NULL), 37 _labelsOn(false) 32 38 { 33 39 _bondColor[0] = _bondColor[1] = _bondColor[2] = 1.0f; … … 75 81 _bondProp->GetProperty()->LightingOff(); 76 82 } 83 if (_labelProp == NULL) { 84 _labelProp = vtkSmartPointer<vtkActor2D>::New(); 85 } 77 86 if (_prop == NULL) { 78 87 _prop = vtkSmartPointer<vtkAssembly>::New(); … … 99 108 _bondMapper->SetResolveCoincidentTopologyToPolygonOffset(); 100 109 _bondMapper->ScalarVisibilityOn(); 110 } 111 if (_labelMapper == NULL) { 112 _labelMapper = vtkSmartPointer<vtkLabelPlacementMapper>::New(); 113 _labelMapper->SetShapeToRoundedRect(); 114 _labelMapper->SetBackgroundColor(1.0, 1.0, 0.7); 115 _labelMapper->SetBackgroundOpacity(0.8); 116 _labelMapper->SetMargin(3); 101 117 } 102 118 … … 117 133 initProp(); 118 134 135 addLabelArray(ds); 119 136 addRadiusArray(ds, _atomScaling, _radiusScale); 120 137 … … 141 158 } 142 159 if (pd->GetNumberOfVerts() > 0) { 160 vtkSmartPointer<vtkPointSetToLabelHierarchy> hier = vtkSmartPointer<vtkPointSetToLabelHierarchy>::New(); 161 hier->SetInput(pd); 162 hier->SetLabelArrayName("labels"); 163 hier->GetTextProperty()->SetColor(0, 0, 0); 164 _labelMapper->SetInputConnection(hier->GetOutputPort()); 165 _labelProp->SetMapper(_labelMapper); 166 143 167 // Atoms 144 168 vtkSmartPointer<vtkSphereSource> sphereSource = vtkSmartPointer<vtkSphereSource>::New(); … … 171 195 } 172 196 197 setAtomLabelVisibility(_labelsOn); 198 173 199 _atomMapper->Update(); 174 200 _bondMapper->Update(); 201 _labelMapper->Update(); 175 202 } 176 203 … … 237 264 238 265 /** 266 * \brief Turn on/off rendering of atom labels 267 */ 268 void Molecule::setAtomLabelVisibility(bool state) 269 { 270 _labelsOn = state; 271 if (_labelProp != NULL) { 272 _labelProp->SetVisibility((state ? 1 : 0)); 273 } 274 } 275 276 /** 239 277 * \brief Turn on/off rendering of the atoms 240 278 */ … … 253 291 if (_bondProp != NULL) { 254 292 _bondProp->SetVisibility((state ? 1 : 0)); 293 } 294 } 295 296 /** 297 * \brief Toggle visibility of the prop 298 */ 299 void Molecule::setVisibility(bool state) 300 { 301 VtkGraphicsObject::setVisibility(state); 302 if (_labelProp != NULL) { 303 if (!state) 304 _labelProp->SetVisibility(0); 305 else 306 setAtomLabelVisibility(_labelsOn); 307 } 308 } 309 310 /** 311 * \brief Set opacity of molecule 312 */ 313 void Molecule::setOpacity(double opacity) 314 { 315 VtkGraphicsObject::setOpacity(opacity); 316 if (_labelMapper != NULL) { 317 _labelMapper->SetBackgroundOpacity(opacity); 255 318 } 256 319 } … … 341 404 if (_tuber != NULL) 342 405 _tuber->SetRadius(scale); 406 } 407 408 void Molecule::addLabelArray(vtkDataSet *dataSet) 409 { 410 vtkDataArray *elements = NULL; 411 if (dataSet->GetPointData() != NULL && 412 dataSet->GetPointData()->GetScalars() != NULL && 413 strcmp(dataSet->GetPointData()->GetScalars()->GetName(), "element") == 0) { 414 elements = dataSet->GetPointData()->GetScalars(); 415 } else { 416 WARN("Can't label atoms without an element array"); 417 } 418 419 vtkSmartPointer<vtkStringArray> labelArray = vtkSmartPointer<vtkStringArray>::New(); 420 labelArray->SetName("labels"); 421 vtkPolyData *pd = vtkPolyData::SafeDownCast(dataSet); 422 if (pd == NULL) { 423 ERROR("DataSet not a PolyData"); 424 return; 425 } 426 for (int i = 0; i < pd->GetNumberOfVerts(); i++) { 427 char buf[32]; 428 if (elements != NULL) { 429 int elt = (int)elements->GetComponent(i, 0); 430 sprintf(buf, "%s%d", g_elementNames[elt], i); 431 } else { 432 sprintf(buf, "%d", i); 433 labelArray->InsertNextValue(buf); 434 } 435 labelArray->InsertNextValue(buf); 436 } 437 dataSet->GetPointData()->AddArray(labelArray); 343 438 } 344 439 -
trunk/packages/vizservers/vtkvis/RpMolecule.h
r3112 r3131 13 13 #include <vtkPolyDataMapper.h> 14 14 #include <vtkActor.h> 15 #include <vtkActor2D.h> 15 16 #include <vtkAssembly.h> 16 17 #include <vtkTubeFilter.h> 17 18 #include <vtkGlyph3D.h> 19 #include <vtkLabelPlacementMapper.h> 18 20 19 21 #include "ColorMap.h" … … 55 57 } 56 58 59 virtual vtkProp *getOverlayProp() 60 { 61 return _labelProp; 62 } 63 57 64 virtual void setClippingPlanes(vtkPlaneCollection *planes); 58 65 … … 77 84 void setBondRadiusScale(double scale); 78 85 86 virtual void setVisibility(bool state); 87 88 virtual void setOpacity(double opacity); 89 79 90 void setAtomVisibility(bool state); 91 92 void setAtomLabelVisibility(bool state); 80 93 81 94 void setBondVisibility(bool state); … … 91 104 virtual void update(); 92 105 106 static void addLabelArray(vtkDataSet *dataSet); 107 93 108 static void addRadiusArray(vtkDataSet *dataSet, AtomScaling scaling, double scaleFactor); 94 109 … … 97 112 AtomScaling _atomScaling; 98 113 ColorMap *_colorMap; 114 bool _labelsOn; 99 115 100 116 vtkSmartPointer<vtkLookupTable> _lut; 101 117 vtkSmartPointer<vtkActor> _atomProp; 102 118 vtkSmartPointer<vtkActor> _bondProp; 119 vtkSmartPointer<vtkActor2D> _labelProp; 103 120 vtkSmartPointer<vtkGlyph3D> _glypher; 104 121 vtkSmartPointer<vtkTubeFilter> _tuber; 105 122 vtkSmartPointer<vtkPolyDataMapper> _atomMapper; 106 123 vtkSmartPointer<vtkPolyDataMapper> _bondMapper; 124 vtkSmartPointer<vtkLabelPlacementMapper> _labelMapper; 107 125 }; 108 126 -
trunk/packages/vizservers/vtkvis/RpVtkGraphicsObject.h
r3092 r3131 165 165 } 166 166 167 virtual vtkProp *getOverlayProp() 168 { 169 return NULL; 170 } 171 167 172 /** 168 173 * \brief Set an additional transform on the prop … … 242 247 243 248 /** 249 * \brief Set 2D aspect ratio scaling 250 * 251 * \param aspect 0=no scaling, otherwise aspect 252 * is horiz/vertical ratio 253 */ 254 virtual void setAspect(double aspect) 255 { 256 ; 257 } 258 259 /** 244 260 * \brief Set the prop scaling 245 261 * … … 251 267 getProp3D()->SetScale(scale); 252 268 } 269 } 270 271 /** 272 * \brief Get the physical bounds of the prop 273 * 274 * If the prop is scaled, these bounds will be 275 * scaled as well 276 */ 277 virtual double *getBounds() 278 { 279 if (getProp() != NULL) 280 return getProp()->GetBounds(); 281 else 282 return NULL; 283 } 284 285 /** 286 * \brief Get the data bounds of the prop 287 * 288 * If the prop is scaled, these bounds will NOT 289 * be scaled, they will reflect the unscaled data 290 * bounds. 291 */ 292 virtual double *getUnscaledBounds() 293 { 294 if (getProp3D() != NULL) { 295 double scale[3]; 296 getProp3D()->GetScale(scale); 297 if (scale[0] == scale[1] && scale[1] == scale[2] && 298 scale[0] == 1.0) { 299 return getBounds(); 300 } else if (getBounds() != NULL) { 301 _unscaledBounds[0] = getBounds()[0] / scale[0]; 302 _unscaledBounds[1] = getBounds()[1] / scale[0]; 303 _unscaledBounds[2] = getBounds()[2] / scale[1]; 304 _unscaledBounds[3] = getBounds()[3] / scale[1]; 305 _unscaledBounds[4] = getBounds()[4] / scale[2]; 306 _unscaledBounds[5] = getBounds()[5] / scale[2]; 307 return _unscaledBounds; 308 } 309 } 310 return getBounds(); 253 311 } 254 312 … … 743 801 DataSet *_dataSet; 744 802 double _dataRange[2]; 803 double _unscaledBounds[6]; 745 804 double _opacity; 746 805 float _color[3]; -
trunk/packages/vizservers/vtkvis/RpVtkRendererGraphicsObjs.h
r2612 r3131 60 60 if (gobj->getProp()) 61 61 _renderer->RemoveViewProp(gobj->getProp()); 62 if (gobj->getOverlayProp()) 63 _renderer->RemoveViewProp(gobj->getOverlayProp()); 62 64 delete gobj; 63 65 … … 100 102 gobj->setDataSet(ds, this); 101 103 102 if (gobj->getProp() == NULL) { 104 if (gobj->getProp() == NULL && 105 gobj->getOverlayProp() == NULL) { 103 106 delete gobj; 104 107 return false; 105 108 } else { 106 _renderer->AddViewProp(gobj->getProp()); 109 if (gobj->getProp()) 110 _renderer->AddViewProp(gobj->getProp()); 111 if (gobj->getOverlayProp()) 112 _renderer->AddViewProp(gobj->getOverlayProp()); 107 113 } 108 114 … … 233 239 do { 234 240 itr->second->setPosition(pos); 241 } while (doAll && ++itr != hashmap.end()); 242 243 resetAxes(); 244 _needsRedraw = true; 245 } 246 247 /** 248 * \brief Set the prop scaling by 2D aspect ratio 249 */ 250 template<class GraphicsObject> 251 void Renderer::setGraphicsObjectAspect(const DataSetId& id, double aspect) 252 { 253 std::tr1::unordered_map<DataSetId, GraphicsObject *>& hashmap = 254 getGraphicsObjectHashmap<GraphicsObject>(); 255 typename std::tr1::unordered_map<DataSetId, GraphicsObject *>::iterator itr; 256 257 bool doAll = false; 258 259 if (id.compare("all") == 0) { 260 itr = hashmap.begin(); 261 doAll = true; 262 } else { 263 itr = hashmap.find(id); 264 } 265 if (itr == hashmap.end()) { 266 ERROR("%s not found: %s", typeid(GraphicsObject).name(), id.c_str()); 267 return; 268 } 269 270 do { 271 itr->second->setAspect(aspect); 235 272 } while (doAll && ++itr != hashmap.end()); 236 273
Note: See TracChangeset
for help on using the changeset viewer.