File: vtkAMRBox.h

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 (178 lines) | stat: -rw-r--r-- 5,166 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
/*=========================================================================

  Program:   Visualization Toolkit
  Module:    $RCSfile: vtkAMRBox.h,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.

=========================================================================*/
// .NAME vtkAMRBox - represents a 3D uniform region in space
// .SECTION Description
// vtkAMRBox is similar to Chombo's Box. It represents a 3D
// region by storing indices for two corners (LoCorner, HiCorner).
// A few utility methods are provided.

#ifndef __vtkAMRBox_h
#define __vtkAMRBox_h

#include "vtkObject.h"

template<int dimension>
struct vtkAMRBoxInitializeHelp;

// Helper to unroll the loop
template<int dimension>
void vtkAMRBoxInitialize(int *LoCorner, int *HiCorner, // member
                         const int *loCorner, const int *hiCorner, // local
                         vtkAMRBoxInitializeHelp<dimension>* = 0) // dummy parameter for vs6
  {
  for(int i=0; i<dimension; ++i)
    {
    LoCorner[i] = loCorner[i];
    HiCorner[i] = hiCorner[i];
    }
  for(int i=dimension; i<(3-dimension); ++i)
    {
    LoCorner[i] = 0;
    HiCorner[i] = 0;
    }
  }

class VTK_FILTERING_EXPORT vtkAMRBox
{
public:
  // public for quick access
  // Description:
  // cell position of the lower cell position and higher cell positon.
  // Eg. LoCorner = {0,0,0}, HiCorner = {0,0,0} is an AMRBox with 1 cell
  int LoCorner[3];
  int HiCorner[3];

  vtkAMRBox()
    {
    vtkAMRBoxInitialize<0>(this->LoCorner, this->HiCorner, 0, 0);
    }

  // \precondition dimensionality >= 2 && dimensionality <= 3
  vtkAMRBox(int dimensionality, const int* loCorner, const int* hiCorner)
    {
    switch(dimensionality)
      {
    case 2:
      vtkAMRBoxInitialize<2>(this->LoCorner, this->HiCorner,
                             loCorner, hiCorner);
      break;
    case 3:
      vtkAMRBoxInitialize<3>(this->LoCorner, this->HiCorner,
                             loCorner, hiCorner);
      break;
    default:
      vtkGenericWarningMacro( "Wrong dimensionality" );
      }
    }

  // Description:
  // Returns the number of cells (aka elements, zones etc.) in
  // the given region (for the specified refinement, see Coarsen()
  // and Refine() ).
  vtkIdType GetNumberOfCells()
    {
    vtkIdType numCells=1;
    for(int i=0; i<3; i++)
      {
      numCells *= HiCorner[i] - LoCorner[i] + 1;
      }
    return numCells;
    }

  // Description:
  // Modify LoCorner and HiCorner by coarsening with the given
  // refinement ratio.
  void Coarsen(int refinement)
    {
    for (int i=0; i<3; i++)
      {
      this->LoCorner[i] =
        ( this->LoCorner[i] < 0 ?
          -abs(this->LoCorner[i]+1)/refinement - 1 :
          this->LoCorner[i]/refinement );
      this->HiCorner[i] =
        ( this->HiCorner[i] < 0 ?
          -abs(this->HiCorner[i]+1)/refinement - 1 :
          this->HiCorner[i]/refinement );
      }
    }

  // Description:
  // Modify LoCorner and HiCorner by refining with the given
  // refinement ratio.
  void Refine(int refinement)
    {
    for (int i=0; i<3; i++)
      {
      this->LoCorner[i] = (this->LoCorner[i]+1)*refinement-1;
      this->HiCorner[i] = (this->HiCorner[i]+1)*refinement-1;
      }
    }

  // Description:
  // Returns non-zero if the box contains the cell with
  // given indices.
  int DoesContainCell(int i, int j, int k)
    {
    return
      i >= this->LoCorner[0] && i <= this->HiCorner[0] &&
      j >= this->LoCorner[1] && j <= this->HiCorner[1] &&
      k >= this->LoCorner[2] && k <= this->HiCorner[2];
    }

  // Description:
  // Returns non-zero if the box contains `box`
  int DoesContainBox(vtkAMRBox const & box) const
    {
    // return DoesContainCell(box.LoCorner) && DoesContainCell(box.HiCorner);
    return box.LoCorner[0] >= this->LoCorner[0]
        && box.LoCorner[1] >= this->LoCorner[1]
        && box.LoCorner[2] >= this->LoCorner[2]
        && box.HiCorner[0] <= this->HiCorner[0]
        && box.HiCorner[1] <= this->HiCorner[1]
        && box.HiCorner[2] <= this->HiCorner[2];
    }

  // Description:
  // Print LoCorner and HiCorner
  void Print(ostream &os)
    {
    os << "LoCorner: " << this->LoCorner[0] << "," << this->LoCorner[1]
      << "," << this->LoCorner[2] << "\n";
    os << "HiCorner: " << this->HiCorner[0] << "," << this->HiCorner[1]
      << "," << this->HiCorner[2] << "\n";
    }

  // Description:
  // Check if cell position is HiCorner
  bool IsHiCorner(const int pos[3]) const
    {
    return this->HiCorner[0] == pos[0]
        && this->HiCorner[1] == pos[1]
        && this->HiCorner[2] == pos[2];
    }

  // Description:
  // Check if cell position is LoCorner
  bool IsLoCorner(const int pos[3]) const
    {
    return this->LoCorner[0] == pos[0]
        && this->LoCorner[1] == pos[1]
        && this->LoCorner[2] == pos[2];
    }
};

#endif