1 /*========================================================================= 2 3 Program: Visualization Toolkit 4 Module: vtkMoleculeMapper.h 5 6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 7 All rights reserved. 8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details. 9 10 This software is distributed WITHOUT ANY WARRANTY; without even 11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 12 PURPOSE. See the above copyright notice for more information. 13 14 =========================================================================*/ 15 /** 16 * @class vtkMoleculeMapper 17 * @brief Mapper that draws vtkMolecule objects 18 * 19 * 20 * vtkMoleculeMapper uses glyphs (display lists) to quickly render a 21 * molecule. 22 */ 23 24 #ifndef vtkMoleculeMapper_h 25 #define vtkMoleculeMapper_h 26 27 #include "vtkDomainsChemistryModule.h" // For export macro 28 #include "vtkMapper.h" 29 #include "vtkNew.h" // For vtkNew 30 31 class vtkActor; 32 class vtkGlyph3DMapper; 33 class vtkIdTypeArray; 34 class vtkMolecule; 35 class vtkPeriodicTable; 36 class vtkPolyData; 37 class vtkPolyDataMapper; 38 class vtkRenderer; 39 class vtkSelection; 40 class vtkSphereSource; 41 class vtkTrivialProducer; 42 43 class VTKDOMAINSCHEMISTRY_EXPORT vtkMoleculeMapper : public vtkMapper 44 { 45 public: 46 static vtkMoleculeMapper* New(); 47 vtkTypeMacro(vtkMoleculeMapper, vtkMapper); 48 void PrintSelf(ostream& os, vtkIndent indent) override; 49 50 ///@{ 51 /** 52 * Get/Set the input vtkMolecule. 53 */ 54 void SetInputData(vtkMolecule* in); 55 vtkMolecule* GetInput(); 56 ///@} 57 58 /** 59 * Set ivars to default ball-and-stick settings. This is equivalent 60 * to the following: 61 * - SetRenderAtoms( true ) 62 * - SetRenderBonds( true ) 63 * - SetAtomicRadiusType( VDWRadius ) 64 * - SetAtomicRadiusScaleFactor( 0.3 ) 65 * - SetBondColorMode( DiscreteByAtom ) 66 * - SetUseMultiCylindersForBonds( true ) 67 * - SetBondRadius( 0.075 ) 68 */ 69 void UseBallAndStickSettings(); 70 71 /** 72 * Set ivars to default van der Waals spheres settings. This is 73 * equivalent to the following: 74 * - SetRenderAtoms( true ) 75 * - SetRenderBonds( true ) 76 * - SetAtomicRadiusType( VDWRadius ) 77 * - SetAtomicRadiusScaleFactor( 1.0 ) 78 * - SetBondColorMode( DiscreteByAtom ) 79 * - SetUseMultiCylindersForBonds( true ) 80 * - SetBondRadius( 0.075 ) 81 */ 82 void UseVDWSpheresSettings(); 83 84 /** 85 * Set ivars to default liquorice stick settings. This is 86 * equivalent to the following: 87 * - SetRenderAtoms( true ) 88 * - SetRenderBonds( true ) 89 * - SetAtomicRadiusType( UnitRadius ) 90 * - SetAtomicRadiusScaleFactor( 0.1 ) 91 * - SetBondColorMode( DiscreteByAtom ) 92 * - SetUseMultiCylindersForBonds( false ) 93 * - SetBondRadius( 0.1 ) 94 */ 95 void UseLiquoriceStickSettings(); 96 97 /** 98 * Set ivars to use fast settings that may be useful for rendering 99 * extremely large molecules where the overall shape is more 100 * important than the details of the atoms/bond. This is equivalent 101 * to the following: 102 * - SetRenderAtoms( true ) 103 * - SetRenderBonds( true ) 104 * - SetAtomicRadiusType( UnitRadius ) 105 * - SetAtomicRadiusScaleFactor( 0.60 ) 106 * - SetBondColorMode( SingleColor ) 107 * - SetBondColor( 50, 50, 50 ) 108 * - SetUseMultiCylindersForBonds( false ) 109 * - SetBondRadius( 0.075 ) 110 */ 111 void UseFastSettings(); 112 113 ///@{ 114 /** 115 * Get/Set whether or not to render atoms. Default: On. 116 */ 117 vtkGetMacro(RenderAtoms, bool); 118 vtkSetMacro(RenderAtoms, bool); 119 vtkBooleanMacro(RenderAtoms, bool); 120 ///@} 121 122 ///@{ 123 /** 124 * Get/Set whether or not to render bonds. Default: On. 125 */ 126 vtkGetMacro(RenderBonds, bool); 127 vtkSetMacro(RenderBonds, bool); 128 vtkBooleanMacro(RenderBonds, bool); 129 ///@} 130 131 ///@{ 132 /** 133 * Get/Set whether or not to render the unit cell lattice, if present. 134 * Default: On. 135 */ 136 vtkGetMacro(RenderLattice, bool); 137 vtkSetMacro(RenderLattice, bool); 138 vtkBooleanMacro(RenderLattice, bool); 139 ///@} 140 141 enum 142 { 143 CovalentRadius = 0, 144 VDWRadius, 145 UnitRadius, 146 CustomArrayRadius 147 }; 148 149 ///@{ 150 /** 151 * Get/Set the type of radius used to generate the atoms. Default: 152 * VDWRadius. If CustomArrayRadius is used, the VertexData array named 153 * 'radii' is used for per-atom radii. 154 */ 155 vtkGetMacro(AtomicRadiusType, int); 156 vtkSetMacro(AtomicRadiusType, int); 157 const char* GetAtomicRadiusTypeAsString(); SetAtomicRadiusTypeToCovalentRadius()158 void SetAtomicRadiusTypeToCovalentRadius() { this->SetAtomicRadiusType(CovalentRadius); } SetAtomicRadiusTypeToVDWRadius()159 void SetAtomicRadiusTypeToVDWRadius() { this->SetAtomicRadiusType(VDWRadius); } SetAtomicRadiusTypeToUnitRadius()160 void SetAtomicRadiusTypeToUnitRadius() { this->SetAtomicRadiusType(UnitRadius); } SetAtomicRadiusTypeToCustomArrayRadius()161 void SetAtomicRadiusTypeToCustomArrayRadius() { this->SetAtomicRadiusType(CustomArrayRadius); } 162 ///@} 163 164 ///@{ 165 /** 166 * Get/Set the uniform scaling factor applied to the atoms. 167 * This is ignored when AtomicRadiusType == CustomArrayRadius. 168 * Default: 0.3. 169 */ 170 vtkGetMacro(AtomicRadiusScaleFactor, float); 171 vtkSetMacro(AtomicRadiusScaleFactor, float); 172 ///@} 173 174 ///@{ 175 /** 176 * Get/Set whether multicylinders will be used to represent multiple 177 * bonds. Default: On. 178 */ 179 vtkGetMacro(UseMultiCylindersForBonds, bool); 180 vtkSetMacro(UseMultiCylindersForBonds, bool); 181 vtkBooleanMacro(UseMultiCylindersForBonds, bool); 182 ///@} 183 184 enum 185 { 186 SingleColor = 0, 187 DiscreteByAtom 188 }; 189 190 ///@{ 191 /** 192 * Get/Set the method by which bonds are colored. 193 194 * If 'SingleColor' is used, all bonds will be the same color. Use 195 * SetBondColor to set the rgb values used. 196 197 * If 'DiscreteByAtom' is selected, each bond is colored using the 198 * same lookup table as the atoms at each end, with a sharp color 199 * boundary at the bond center. 200 */ 201 vtkGetMacro(BondColorMode, int); 202 vtkSetClampMacro(BondColorMode, int, SingleColor, DiscreteByAtom); SetBondColorModeToSingleColor()203 void SetBondColorModeToSingleColor() { this->SetBondColorMode(SingleColor); } SetBondColorModeToDiscreteByAtom()204 void SetBondColorModeToDiscreteByAtom() { this->SetBondColorMode(DiscreteByAtom); } 205 const char* GetBondColorModeAsString(); 206 ///@} 207 208 ///@{ 209 /** 210 * Get/Set the method by which atoms are colored. 211 * 212 * If 'SingleColor' is used, all atoms will have the same color. Use 213 * SetAtomColor to set the rgb values to be used. 214 * 215 * If 'DiscreteByAtom' is selected, each atom is colored using the 216 * internal lookup table. 217 */ 218 vtkGetMacro(AtomColorMode, int); 219 vtkSetClampMacro(AtomColorMode, int, SingleColor, DiscreteByAtom); 220 ///@} 221 222 ///@{ 223 /** 224 * Get/Set the color of the atoms as an rgb tuple. 225 * Default: {150, 150, 150} (grey) 226 */ 227 vtkGetVector3Macro(AtomColor, unsigned char); 228 vtkSetVector3Macro(AtomColor, unsigned char); 229 ///@} 230 231 ///@{ 232 /** 233 * Get/Set the color of the bonds as an rgb tuple. 234 * Default: {50, 50, 50} (dark grey) 235 */ 236 vtkGetVector3Macro(BondColor, unsigned char); 237 vtkSetVector3Macro(BondColor, unsigned char); 238 ///@} 239 240 ///@{ 241 /** 242 * Get/Set the radius of the bond cylinders. Default: 0.075 243 */ 244 vtkGetMacro(BondRadius, float); 245 vtkSetMacro(BondRadius, float); 246 ///@} 247 248 ///@{ 249 /** 250 * Get/Set the color of the bonds as an rgb tuple. 251 * Default: {255, 255, 255} (white) 252 */ 253 vtkGetVector3Macro(LatticeColor, unsigned char); 254 vtkSetVector3Macro(LatticeColor, unsigned char); 255 ///@} 256 257 ///@{ 258 /** 259 * Extract the ids atoms and/or bonds rendered by this molecule from a 260 * vtkSelection object. The vtkIdTypeArray 261 */ 262 virtual void GetSelectedAtomsAndBonds( 263 vtkSelection* selection, vtkIdTypeArray* atomIds, vtkIdTypeArray* bondIds); GetSelectedAtoms(vtkSelection * selection,vtkIdTypeArray * atomIds)264 virtual void GetSelectedAtoms(vtkSelection* selection, vtkIdTypeArray* atomIds) 265 { 266 this->GetSelectedAtomsAndBonds(selection, atomIds, nullptr); 267 } GetSelectedBonds(vtkSelection * selection,vtkIdTypeArray * bondIds)268 virtual void GetSelectedBonds(vtkSelection* selection, vtkIdTypeArray* bondIds) 269 { 270 this->GetSelectedAtomsAndBonds(selection, nullptr, bondIds); 271 } 272 ///@} 273 274 ///@{ 275 /** 276 * Reimplemented from base class 277 */ 278 void Render(vtkRenderer*, vtkActor*) override; 279 void ReleaseGraphicsResources(vtkWindow*) override; 280 double* GetBounds() override; GetBounds(double bounds[6])281 void GetBounds(double bounds[6]) override { vtkAbstractMapper3D::GetBounds(bounds); } 282 int FillInputPortInformation(int port, vtkInformation* info) override; GetSupportsSelection()283 bool GetSupportsSelection() override { return true; } 284 ///@} 285 286 ///@{ 287 /** 288 * Get/Set the atomic radius array name. Default: "radii" 289 * It is only used when AtomicRadiusType is set to CustomArrayRadius. 290 */ 291 vtkGetStringMacro(AtomicRadiusArrayName); 292 vtkSetStringMacro(AtomicRadiusArrayName); 293 ///@} 294 295 /** 296 * Helper method to set ScalarMode on both AtomGlyphMapper and BondGlyphMapper. 297 * true means VTK_COLOR_MODE_MAP_SCALARS, false VTK_COLOR_MODE_DIRECT_SCALARS. 298 */ 299 virtual void SetMapScalars(bool map); 300 301 /** 302 * Accessor to internal structure. This is exposed to make it available for ray tracers. 303 */ GetPeriodicTable()304 vtkPeriodicTable* GetPeriodicTable() { return this->PeriodicTable; } 305 306 protected: 307 vtkMoleculeMapper(); 308 ~vtkMoleculeMapper() override; 309 310 ///@{ 311 /** 312 * Customize atom rendering 313 */ 314 bool RenderAtoms; 315 int AtomicRadiusType; 316 float AtomicRadiusScaleFactor; 317 char* AtomicRadiusArrayName; 318 int AtomColorMode; 319 unsigned char AtomColor[3]; 320 ///@} 321 322 ///@{ 323 /** 324 * Customize bond rendering 325 */ 326 bool RenderBonds; 327 int BondColorMode; 328 bool UseMultiCylindersForBonds; 329 float BondRadius; 330 unsigned char BondColor[3]; 331 ///@} 332 333 bool RenderLattice; 334 335 /** 336 * Internal render methods 337 */ 338 void GlyphRender(vtkRenderer* ren, vtkActor* act); 339 340 ///@{ 341 /** 342 * Cached variables and update methods 343 */ 344 vtkNew<vtkPolyData> AtomGlyphPolyData; 345 vtkNew<vtkTrivialProducer> AtomGlyphPointOutput; 346 vtkNew<vtkPolyData> BondGlyphPolyData; 347 vtkNew<vtkTrivialProducer> BondGlyphPointOutput; 348 bool GlyphDataInitialized; 349 virtual void UpdateGlyphPolyData(); 350 virtual void UpdateAtomGlyphPolyData(); 351 virtual void UpdateBondGlyphPolyData(); 352 ///@} 353 354 ///@{ 355 /** 356 * Internal mappers 357 */ 358 vtkNew<vtkGlyph3DMapper> AtomGlyphMapper; 359 vtkNew<vtkGlyph3DMapper> BondGlyphMapper; 360 ///@} 361 362 unsigned char LatticeColor[3]; 363 vtkNew<vtkPolyData> LatticePolyData; 364 vtkNew<vtkPolyDataMapper> LatticeMapper; 365 virtual void UpdateLatticePolyData(); 366 367 /** 368 * Periodic table for lookups 369 */ 370 vtkNew<vtkPeriodicTable> PeriodicTable; 371 372 private: 373 vtkMoleculeMapper(const vtkMoleculeMapper&) = delete; 374 void operator=(const vtkMoleculeMapper&) = delete; 375 }; 376 377 #endif 378