File: vtkPExtractArraysOverTime.cxx

package info (click to toggle)
paraview 3.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: lenny
  • size: 124,600 kB
  • ctags: 133,728
  • sloc: cpp: 958,817; ansic: 509,658; tcl: 45,787; xml: 23,401; python: 19,574; perl: 3,112; yacc: 1,787; java: 1,517; sh: 665; asm: 471; lex: 400; makefile: 168; objc: 28
file content (190 lines) | stat: -rw-r--r-- 6,381 bytes parent folder | download
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    $RCSfile: vtkPExtractArraysOverTime.cxx,v $

  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
  All rights reserved.
  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
     PURPOSE.  See the above copyright notice for more information.

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

#include "vtkInformationVector.h"
#include "vtkMultiProcessController.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkRectilinearGrid.h"
#include "vtkUnsignedCharArray.h"

vtkCxxRevisionMacro(vtkPExtractArraysOverTime, "$Revision: 1.7 $");
vtkStandardNewMacro(vtkPExtractArraysOverTime);

vtkCxxSetObjectMacro(vtkPExtractArraysOverTime, Controller, vtkMultiProcessController);

//----------------------------------------------------------------------------
vtkPExtractArraysOverTime::vtkPExtractArraysOverTime()
{
  this->Controller = 0;
  this->SetController(vtkMultiProcessController::GetGlobalController());
}

//----------------------------------------------------------------------------
vtkPExtractArraysOverTime::~vtkPExtractArraysOverTime()
{
  this->SetController(0);
}
//----------------------------------------------------------------------------
void vtkPExtractArraysOverTime::PrintSelf(ostream& os, vtkIndent indent)
{
  this->Superclass::PrintSelf(os,indent);

  os << indent << "Controller: " << this->Controller << endl;
}

//----------------------------------------------------------------------------
void vtkPExtractArraysOverTime::PostExecute(
  vtkInformation* request,
  vtkInformationVector** inputVector,
  vtkInformationVector* outputVector)
{
  vtkInformation* outInfo = outputVector->GetInformationObject(0);
  vtkRectilinearGrid *output = vtkRectilinearGrid::GetData(outInfo);

  int procid = 0;
  int numProcs = 1;
  if ( this->Controller )
    {
    procid = this->Controller->GetLocalProcessId();
    numProcs = this->Controller->GetNumberOfProcesses();
    }

  if (numProcs > 1)
    {
    if (procid == 0)
      {
      for (int i = 1; i < numProcs; i++)
        {
        vtkRectilinearGrid* remoteOutput = vtkRectilinearGrid::New();
        this->Controller->Receive(remoteOutput, i, EXCHANGE_DATA);
        this->AddRemoteData(remoteOutput, output);
        remoteOutput->Delete();
        }

      // Zero out invalid time steps and report error if necessary.
      bool error = false;
      vtkUnsignedCharArray* validPts = vtkUnsignedCharArray::SafeDownCast(
        output->GetPointData()->GetArray("vtkValidPointMask"));
      if (validPts)
        {
        int* dims = output->GetDimensions();
        for (int i=0; i<dims[0]; i++)
          {
          if (!validPts->GetValue(i))
            {
            error = true;
            vtkDataSetAttributes* outPointData = output->GetPointData();
            int numArrays = outPointData->GetNumberOfArrays();
            for (int aidx=0; aidx<numArrays; aidx++)
              {
              vtkDataArray* array = outPointData->GetArray(aidx);
              // If array is not null and it is not the time array
              if (array &&
                  (!array->GetName() ||
                   strncmp(array->GetName(), "Time", 4) != 0))
                {
                int numComps = array->GetNumberOfComponents();
                if (numComps > 0)
                  {
                  // This should also initialize to 0
                  double* val = new double[numComps];
                  array->SetTuple(i, val);
                  delete[] val;
                  }
                }
              }
            }
          }
        }
      if (error)
        {
        //this is not necessarily an error
        //when the probe misses invalid and zeroing is correct
        //vtkErrorMacro("One or more selected items could not be found. "
        //              "Array values for those items are set to 0");
        }
      }
    else
      {
      this->Controller->Send(output, 0, EXCHANGE_DATA);
      }
    }

  this->Superclass::PostExecute(request, inputVector, outputVector);
}

//----------------------------------------------------------------------------
void vtkPExtractArraysOverTime::AddRemoteData(vtkRectilinearGrid* routput,
                                              vtkRectilinearGrid* output)
{
  int* rDims = routput->GetDimensions();
  int* dims = output->GetDimensions();
  if (dims[0] != rDims[0])
    {
    vtkWarningMacro("Tried to add remote dataset of different length. "
                    "Skipping");
    return;
    }
  
  vtkUnsignedCharArray* rValidPts = vtkUnsignedCharArray::SafeDownCast(
    routput->GetPointData()->GetArray("vtkValidPointMask"));

  // Copy the valid values
  if (rValidPts)
    {
    for (int i=0; i<dims[0]; i++)
      {
      if (rValidPts->GetValue(i))
        {
        vtkDataSetAttributes* outPointData = output->GetPointData();
        vtkDataSetAttributes* remotePointData = routput->GetPointData();
        // Copy arrays from remote to current
        int numRArrays = remotePointData->GetNumberOfArrays();
        for (int aidx=0; aidx<numRArrays; aidx++)
          {
          const char* name = 0;
          vtkAbstractArray* raa = remotePointData->GetAbstractArray(aidx);
          if (raa)
            {
            name = raa->GetName();
            }
          if (name)
            {
            vtkAbstractArray* aa = outPointData->GetAbstractArray(name);
            // Create the output array if necessary
            if (!aa)
              {
              aa = raa->NewInstance();
              aa->DeepCopy(raa);
              aa->SetName(name);
              outPointData->AddArray(aa);
              aa->UnRegister(0);
              }
            if (raa->GetNumberOfTuples() > i)
              {
              aa->InsertTuple(i, i, raa);
              }
            else
              {
              //cerr << (raa->GetName()?raa->GetName():"NONAME") <<" has only " << raa->GetNumberOfTuples() << " and looking for value at " << i << endl;
              }
            }
          }
        }
      }
    }
}