File: pqSurfaceRepresentationBehavior.cxx

package info (click to toggle)
paraview 5.1.2%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 221,108 kB
  • ctags: 236,092
  • sloc: cpp: 2,416,026; ansic: 190,891; python: 99,856; xml: 81,001; tcl: 46,915; yacc: 5,039; java: 4,413; perl: 3,108; sh: 1,974; lex: 1,926; f90: 748; asm: 471; pascal: 228; makefile: 198; objc: 83; fortran: 31
file content (161 lines) | stat: -rw-r--r-- 6,556 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*=========================================================================

   Program: ParaView
   Module:  pqSurfaceRepresentationBehavior.cxx

   Copyright (c) 2005,2006 Sandia Corporation, Kitware Inc.
   All rights reserved.

   ParaView is a free software; you can redistribute it and/or modify it
   under the terms of the ParaView license version 1.2.

   See License_v1.2.txt for the full ParaView license.
   A copy of this license can be obtained by contacting
   Kitware Inc.
   28 Corporate Drive
   Clifton Park, NY 12065
   USA

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

========================================================================*/
#include "pqSurfaceRepresentationBehavior.h"

#include "pqApplicationCore.h"
#include "pqObjectBuilder.h"
#include "pqPipelineRepresentation.h"
#include "pqRepresentation.h"
#include "pqSMAdaptor.h"
#include "pqScalarsToColors.h"
#include "pqServerManagerModel.h"
#include "pqView.h"
#include "vtkPVArrayInformation.h"
#include "vtkPVDataInformation.h"
#include "vtkPVDataSetAttributesInformation.h"
#include "vtkSMProperty.h"
#include "vtkSMPropertyHelper.h"
#include "vtkSMProxy.h"
#include "vtkSMRepresentationProxy.h"
#include "vtkSMSourceProxy.h"

#include <QVariant>

//-----------------------------------------------------------------------------
pqSurfaceRepresentationBehavior::pqSurfaceRepresentationBehavior(QObject* parentObject)
  : Superclass(parentObject)
{
  QObject::connect(pqApplicationCore::instance()->getServerManagerModel(),
                   SIGNAL(viewAdded(pqView*)),
                   this, SLOT(onViewAdded(pqView*)));
}

//-----------------------------------------------------------------------------
void pqSurfaceRepresentationBehavior::onRepresentationAdded(pqRepresentation* rep)
{
  pqPipelineRepresentation* pipelineRep = qobject_cast<pqPipelineRepresentation*>(rep);
  vtkSMRepresentationProxy* smRep =
      vtkSMRepresentationProxy::SafeDownCast(rep->getProxy());
  if(pipelineRep && smRep)
    {

    // ------------------------------------------------------------------------
    // Let's pick a reptesentation type that we like instead of the default one
    // We will use our own set of priority order.
    // ------------------------------------------------------------------------
    QList<QVariant> list =
        pqSMAdaptor::getEnumerationPropertyDomain(
          pipelineRep->getProxy()->GetProperty("Representation"));

    // Set a representation type based on a priority
    int priority = 0;
    std::string finalValue;
    foreach(QVariant v, list)
      {
      if(v.toString() == "Surface" && priority < 1)
        {
        finalValue = "Surface";
        priority = 1;
        }

      if(v.toString() == "Slices" && priority < 2)
        {
        finalValue = "Slices";
        priority = 2;
        }

      }

    // Apply the new representation type is any available
    if(!finalValue.empty())
      {
      pipelineRep->setRepresentation(finalValue.c_str());
      }
    // ------------------------------------------------------------------------

    // ------------------------------------------------------------------------
    // Let's select some data array by default
    // ------------------------------------------------------------------------

    vtkSMProxy* input = vtkSMPropertyHelper(smRep, "Input").GetAsProxy();
    vtkSMSourceProxy *sourceProxy = vtkSMSourceProxy::SafeDownCast(input);
    if(sourceProxy)
      {
      vtkPVDataInformation *dataInfo = sourceProxy->GetDataInformation();

      if(dataInfo->GetPointDataInformation()->GetNumberOfArrays() > 0)
        {
        const char* scalarName =
            dataInfo->GetPointDataInformation()->GetArrayInformation(0)->GetName();
        pipelineRep->colorByArray(scalarName, 0); // 0: POINT_DATA / 1:CELL_DATA

        // --------------------------------------------------------------------
        // Let's change the data range for the lookup table to remove 1/8 of
        // the data range from the min and the max of the scalar range
        // --------------------------------------------------------------------
        QPair<double, double> range = pipelineRep->getLookupTable()->getScalarRange();
        double min = range.first + (range.second - range.first)/8;
        double max = range.second - (range.second - range.first)/8;

        // Apply changes
        pipelineRep->getLookupTable()->setScalarRangeLock(true);
        pipelineRep->getLookupTable()->setScalarRange(min, max);
        }
      else if (dataInfo->GetCellDataInformation()->GetNumberOfArrays() > 0)
        {
        const char* scalarName =
            dataInfo->GetCellDataInformation()->GetArrayInformation(0)->GetName();
        pipelineRep->colorByArray(scalarName, 1); // 0: POINT_DATA / 1:CELL_DATA

        // --------------------------------------------------------------------
        // Let's change the data range for the lookup table to remove 1/8 of
        // the data range from the min and the max of the scalar range
        // --------------------------------------------------------------------
        QPair<double, double> range = pipelineRep->getLookupTable()->getScalarRange();
        double min = range.first + (range.second - range.first)/8;
        double max = range.second - (range.second - range.first)/8;

        // Apply changes
        pipelineRep->getLookupTable()->setScalarRangeLock(true);
        pipelineRep->getLookupTable()->setScalarRange(min, max);
        }
      }
    }
}

//-----------------------------------------------------------------------------
void pqSurfaceRepresentationBehavior::onViewAdded(pqView* view)
{
  QObject::connect(view, SIGNAL(representationAdded(pqRepresentation*)),
                   this, SLOT(onRepresentationAdded(pqRepresentation*)),
                   Qt::QueuedConnection);
}