Changeset 3844 for branches/1.3/packages/vizservers/vtkvis/Molecule.cpp
- Timestamp:
- Jul 26, 2013, 6:00:09 PM (11 years ago)
- Location:
- branches/1.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1.3
-
branches/1.3/packages/vizservers/vtkvis/Molecule.cpp
r3693 r3844 29 29 #include <vtkLabelPlacementMapper.h> 30 30 #include <vtkTextProperty.h> 31 #include <vtkTransformPolyDataFilter.h> 31 32 32 33 #include "Molecule.h" … … 108 109 _atomProp->GetProperty()->SetOpacity(_opacity); 109 110 _atomProp->GetProperty()->SetAmbient(.2); 111 _atomProp->GetProperty()->SetSpecular(.2); 112 _atomProp->GetProperty()->SetSpecularPower(80.0); 110 113 if (!_lighting) 111 114 _atomProp->GetProperty()->LightingOff(); … … 121 124 _bondProp->GetProperty()->SetOpacity(_opacity); 122 125 _bondProp->GetProperty()->SetAmbient(.2); 126 _bondProp->GetProperty()->SetSpecular(.2); 127 _bondProp->GetProperty()->SetSpecularPower(80.0); 123 128 if (!_lighting) 124 129 _bondProp->GetProperty()->LightingOff(); … … 178 183 addLabelArray(ds); 179 184 addRadiusArray(ds, _atomScaling, _radiusScale); 185 computeBonds(ds); 180 186 181 187 vtkPolyData *pd = vtkPolyData::SafeDownCast(ds); … … 231 237 _labelHierarchy = vtkSmartPointer<vtkPointSetToLabelHierarchy>::New(); 232 238 } 233 #ifdef USE_VTK6 234 _labelHierarchy->SetInputData(pd); 239 if (_labelTransform == NULL) { 240 _labelTransform = vtkSmartPointer<vtkTransform>::New(); 241 } 242 vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter = vtkSmartPointer<vtkTransformPolyDataFilter>::New(); 243 #ifdef USE_VTK6 244 transformFilter->SetInputData(pd); 235 245 #else 236 _labelHierarchy->SetInput(pd);246 transformFilter->SetInput(pd); 237 247 #endif 248 transformFilter->SetTransform(_labelTransform); 249 _labelHierarchy->SetInputConnection(transformFilter->GetOutputPort()); 238 250 _labelHierarchy->SetLabelArrayName("_atom_labels"); 239 251 _labelHierarchy->GetTextProperty()->SetColor(0, 0, 0); … … 255 267 _atomMapper->SetInputConnection(pd->GetProducerPort()); 256 268 #endif 257 if (ds->GetPointData() != NULL && 258 ds->GetPointData()->GetVectors() != NULL) { 259 _atomMapper->SetScaleArray(vtkDataSetAttributes::VECTORS); 260 _atomMapper->SetScaleModeToScaleByMagnitude(); 261 _atomMapper->ScalingOn(); 262 } else { 263 _atomMapper->SetScaleModeToNoDataScaling(); 264 _atomMapper->ScalingOff(); 265 } 269 _atomMapper->SetScaleArray("_radii"); 270 _atomMapper->SetScaleModeToScaleByMagnitude(); 271 _atomMapper->ScalingOn(); 266 272 _atomMapper->OrientOff(); 267 273 … … 283 289 if (pd->GetNumberOfLines() > 0) { 284 290 _bondMapper->Update(); 291 } 292 } 293 294 void Molecule::updateLabelTransform() 295 { 296 if (_labelTransform != NULL && getAssembly() != NULL) { 297 _labelTransform->SetMatrix(getAssembly()->GetMatrix()); 285 298 } 286 299 } … … 797 810 if (_atomMapper != NULL) { 798 811 assert(ds->GetPointData() != NULL && 799 ds->GetPointData()->Get Vectors() != NULL);812 ds->GetPointData()->GetArray("_radii") != NULL); 800 813 _atomMapper->SetScaleModeToScaleByMagnitude(); 801 _atomMapper->SetScaleArray( vtkDataSetAttributes::VECTORS);814 _atomMapper->SetScaleArray("_radii"); 802 815 _atomMapper->ScalingOn(); 803 816 } … … 887 900 bondPoints->InsertNextPoint(newPt1); 888 901 902 #ifdef DEBUG 889 903 TRACE("Bond %d: (%g,%g,%g)-(%g,%g,%g)-(%g,%g,%g)", i, 890 904 pt0[0], pt0[1], pt0[2], 891 905 center[0], center[1], center[2], 892 906 pt1[0], pt1[1], pt1[2]); 907 #endif 893 908 894 909 double vec[3]; … … 898 913 bondVectors->InsertNextTupleValue(vec); 899 914 bondVectors->InsertNextTupleValue(vec); 915 #ifdef DEBUG 900 916 TRACE("Bond %d, vec: %g,%g,%g", i, vec[0], vec[1], vec[2]); 917 #endif 901 918 902 919 double scale[3]; … … 910 927 if (elements != NULL) { 911 928 int element = (int)elements->GetComponent(pts[0], 0); 929 #ifdef DEBUG 912 930 TRACE("Bond %d, elt 0: %d", i, element); 931 #endif 913 932 bondElements->InsertNextValue(element); 914 933 element = (int)elements->GetComponent(pts[1], 0); 934 #ifdef DEBUG 915 935 TRACE("Bond %d, elt 1: %d", i, element); 936 #endif 916 937 bondElements->InsertNextValue(element); 917 938 } … … 984 1005 ; 985 1006 } 986 vtkSmartPointer<vtkFloatArray> radii = vtkSmartPointer<vtkFloatArray>::New();987 radii->SetName("_radii");988 radii->SetNumberOfComponents(3);989 1007 vtkPolyData *pd = vtkPolyData::SafeDownCast(dataSet); 990 1008 if (pd == NULL) { … … 992 1010 return; 993 1011 } 1012 vtkDataArray *array = dataSet->GetPointData()->GetArray("_radii"); 1013 vtkSmartPointer<vtkFloatArray> radii; 1014 if (array == NULL) { 1015 radii = vtkSmartPointer<vtkFloatArray>::New(); 1016 radii->SetName("_radii"); 1017 radii->SetNumberOfComponents(1); 1018 radii->SetNumberOfValues(pd->GetNumberOfPoints()); 1019 } else { 1020 radii = vtkFloatArray::SafeDownCast(array); 1021 assert(radii != NULL); 1022 } 994 1023 for (int i = 0; i < pd->GetNumberOfPoints(); i++) { 995 float tuple[3]; 996 tuple[1] = tuple[2] = 0; 1024 float value; 997 1025 if (elements != NULL && radiusSource != NULL) { 998 1026 int elt = (int)elements->GetComponent(i, 0); 999 tuple[0]= radiusSource[elt] * scaleFactor;1027 value = radiusSource[elt] * scaleFactor; 1000 1028 } else { 1001 tuple[0] = scaleFactor; 1002 } 1003 radii->InsertNextTupleValue(tuple); 1004 } 1005 dataSet->GetPointData()->SetVectors(radii); 1029 value = scaleFactor; 1030 } 1031 radii->SetValue(i, value); 1032 } 1033 radii->Modified(); 1034 if (array == NULL) { 1035 dataSet->GetPointData()->AddArray(radii); 1036 } 1006 1037 } 1007 1038 … … 1037 1068 return elementCmap; 1038 1069 } 1070 1071 int Molecule::computeBonds(vtkDataSet *dataSet, float tolerance) 1072 { 1073 vtkPolyData *pd = vtkPolyData::SafeDownCast(dataSet); 1074 if (pd == NULL) { 1075 ERROR("DataSet not a PolyData"); 1076 return -1; 1077 } 1078 1079 if (pd->GetNumberOfPoints() < 2 || 1080 pd->GetNumberOfLines() > 0) { 1081 return 0; 1082 } 1083 1084 vtkDataArray *elements = NULL; 1085 if (pd->GetPointData() != NULL && 1086 pd->GetPointData()->GetScalars() != NULL && 1087 strcmp(pd->GetPointData()->GetScalars()->GetName(), "element") == 0) { 1088 elements = pd->GetPointData()->GetScalars(); 1089 } else { 1090 TRACE("Can't compute bonds without an element array"); 1091 return -1; 1092 } 1093 int numAtoms = pd->GetNumberOfPoints(); 1094 vtkSmartPointer<vtkCellArray> cells = vtkSmartPointer<vtkCellArray>::New(); 1095 for (int i = 0; i < numAtoms; i++) { 1096 double pt1[3]; 1097 int elem1 = (int)elements->GetComponent(i, 0); 1098 float r1 = g_covalentRadii[elem1]; 1099 pd->GetPoint(i, pt1); 1100 for (int j = i+1; j < numAtoms; j++) { 1101 float r2, dist; 1102 double pt2[3]; 1103 int elem2 = (int)elements->GetComponent(j, 0); 1104 1105 if (elem1 == 1 && elem2 == 1) 1106 continue; 1107 1108 r2 = g_covalentRadii[elem2]; 1109 pd->GetPoint(j, pt2); 1110 1111 double x = pt1[0] - pt2[0]; 1112 double y = pt1[1] - pt2[1]; 1113 double z = pt1[2] - pt2[2]; 1114 dist = (float)sqrt(x*x + y*y + z*z); 1115 //TRACE("i=%d,j=%d elem1=%d,elem2=%d r1=%g,r2=%g, dist=%g", i, j, elem1, elem2, r1, r2, dist); 1116 if (dist < (r1 + r2 + tolerance)) { 1117 vtkIdType pts[2]; 1118 pts[0] = i; 1119 pts[1] = j; 1120 cells->InsertNextCell(2, pts); 1121 } 1122 } 1123 } 1124 1125 if (cells->GetNumberOfCells() > 0) { 1126 pd->SetLines(cells); 1127 } 1128 1129 TRACE("Generated %d bonds", cells->GetNumberOfCells()); 1130 return cells->GetNumberOfCells(); 1131 }
Note: See TracChangeset
for help on using the changeset viewer.