Ignore:
Timestamp:
Jul 13, 2013 2:28:43 AM (11 years ago)
Author:
ldelgass
Message:

Fix molecule labels when molecule actors have been transformed. Optimize
setting scales by reusing allocated array. Use specular lighting on molecule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/packages/vizservers/vtkvis/Molecule.cpp

    r3693 r3795  
    2929#include <vtkLabelPlacementMapper.h>
    3030#include <vtkTextProperty.h>
     31#include <vtkTransformPolyDataFilter.h>
    3132
    3233#include "Molecule.h"
     
    108109        _atomProp->GetProperty()->SetOpacity(_opacity);
    109110        _atomProp->GetProperty()->SetAmbient(.2);
     111        _atomProp->GetProperty()->SetSpecular(.2);
     112        _atomProp->GetProperty()->SetSpecularPower(80.0);
    110113        if (!_lighting)
    111114            _atomProp->GetProperty()->LightingOff();
     
    121124        _bondProp->GetProperty()->SetOpacity(_opacity);
    122125        _bondProp->GetProperty()->SetAmbient(.2);
     126        _bondProp->GetProperty()->SetSpecular(.2);
     127        _bondProp->GetProperty()->SetSpecularPower(80.0);
    123128        if (!_lighting)
    124129            _bondProp->GetProperty()->LightingOff();
     
    231236                _labelHierarchy = vtkSmartPointer<vtkPointSetToLabelHierarchy>::New();
    232237            }
    233 #ifdef USE_VTK6
    234             _labelHierarchy->SetInputData(pd);
     238            if (_labelTransform == NULL) {
     239                _labelTransform = vtkSmartPointer<vtkTransform>::New();
     240            }
     241            vtkSmartPointer<vtkTransformPolyDataFilter> transformFilter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
     242#ifdef USE_VTK6             
     243            transformFilter->SetInputData(pd);
    235244#else
    236             _labelHierarchy->SetInput(pd);
     245            transformFilter->SetInput(pd);
    237246#endif
     247            transformFilter->SetTransform(_labelTransform);
     248            _labelHierarchy->SetInputConnection(transformFilter->GetOutputPort());
    238249            _labelHierarchy->SetLabelArrayName("_atom_labels");
    239250            _labelHierarchy->GetTextProperty()->SetColor(0, 0, 0);
     
    255266            _atomMapper->SetInputConnection(pd->GetProducerPort());
    256267#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             }
     268            _atomMapper->SetScaleArray("_radii");
     269            _atomMapper->SetScaleModeToScaleByMagnitude();
     270            _atomMapper->ScalingOn();
    266271            _atomMapper->OrientOff();
    267272
     
    283288    if (pd->GetNumberOfLines() > 0) {
    284289        _bondMapper->Update();
     290    }
     291}
     292
     293void Molecule::updateLabelTransform()
     294{
     295    if (_labelTransform != NULL && getAssembly() != NULL) {
     296        _labelTransform->SetMatrix(getAssembly()->GetMatrix());
    285297    }
    286298}
     
    797809        if (_atomMapper != NULL) {
    798810             assert(ds->GetPointData() != NULL &&
    799                     ds->GetPointData()->GetVectors() != NULL);
     811                    ds->GetPointData()->GetArray("_radii") != NULL);
    800812            _atomMapper->SetScaleModeToScaleByMagnitude();
    801             _atomMapper->SetScaleArray(vtkDataSetAttributes::VECTORS);
     813            _atomMapper->SetScaleArray("_radii");
    802814            _atomMapper->ScalingOn();
    803815        }
     
    984996        ;
    985997    }
    986     vtkSmartPointer<vtkFloatArray> radii = vtkSmartPointer<vtkFloatArray>::New();
    987     radii->SetName("_radii");
    988     radii->SetNumberOfComponents(3);
    989998    vtkPolyData *pd = vtkPolyData::SafeDownCast(dataSet);
    990999    if (pd == NULL) {
     
    9921001        return;
    9931002    }
     1003    vtkDataArray *array = dataSet->GetPointData()->GetArray("_radii");
     1004    vtkSmartPointer<vtkFloatArray> radii;
     1005    if (array == NULL) {
     1006        radii = vtkSmartPointer<vtkFloatArray>::New();
     1007        radii->SetName("_radii");
     1008        radii->SetNumberOfComponents(1);
     1009        radii->SetNumberOfValues(pd->GetNumberOfPoints());
     1010    } else {
     1011        radii = vtkFloatArray::SafeDownCast(array);
     1012        assert(radii != NULL);
     1013    }
    9941014    for (int i = 0; i < pd->GetNumberOfPoints(); i++) {
    995         float tuple[3];
    996         tuple[1] = tuple[2] = 0;
     1015        float value;
    9971016        if (elements != NULL && radiusSource != NULL) {
    9981017            int elt = (int)elements->GetComponent(i, 0);
    999             tuple[0] = radiusSource[elt] * scaleFactor;
     1018            value = radiusSource[elt] * scaleFactor;
    10001019        } else {
    1001             tuple[0] = scaleFactor;
    1002         }
    1003         radii->InsertNextTupleValue(tuple);
    1004     }
    1005     dataSet->GetPointData()->SetVectors(radii);
     1020            value = scaleFactor;
     1021        }
     1022        radii->SetValue(i, value);
     1023    }
     1024    radii->Modified();
     1025    if (array == NULL) {
     1026        dataSet->GetPointData()->AddArray(radii);
     1027    }
    10061028}
    10071029
Note: See TracChangeset for help on using the changeset viewer.