GOFIGURE2  0.9.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
vtkPlaneCutter.h
Go to the documentation of this file.
1 /*=========================================================================
2  Authors: The GoFigure Dev. Team.
3  at Megason Lab, Systems biology, Harvard Medical school, 2009-11
4 
5  Copyright (c) 2009-11, President and Fellows of Harvard College.
6  All rights reserved.
7 
8  Redistribution and use in source and binary forms, with or without
9  modification, are permitted provided that the following conditions are met:
10 
11  Redistributions of source code must retain the above copyright notice,
12  this list of conditions and the following disclaimer.
13  Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16  Neither the name of the President and Fellows of Harvard College
17  nor the names of its contributors may be used to endorse or promote
18  products derived from this software without specific prior written
19  permission.
20 
21  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23  THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
25  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26  OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27  OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
30  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 
33 =========================================================================*/
34 
35 #ifndef __vtkPlaneCutter_h
36 #define __vtkPlaneCutter_h
37 
38 #include "vtkCutter.h"
39 #include "vtkInformation.h"
40 #include "vtkInformationVector.h"
41 
42 class vtkPlaneCutter : public vtkCutter
43 {
44 public:
45  vtkTypeMacro(vtkPlaneCutter,vtkCutter);
46 
47  static vtkPlaneCutter *New();
48 
49 protected:
50  vtkPlaneCutter(vtkImplicitFunction *cf=NULL) : vtkCutter(cf) {}
51  virtual ~vtkPlaneCutter() {}
52 
53  virtual int RequestData(
54  vtkInformation *request,
55  vtkInformationVector **inputVector,
56  vtkInformationVector *outputVector)
57  {
58  vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
59 
60  // get the input and output
61  vtkDataSet *input = vtkDataSet::SafeDownCast(
62  inInfo->Get(vtkDataObject::DATA_OBJECT()));
63 
64  if (!this->CutFunction)
65  {
66  vtkErrorMacro("No cut function specified");
67  return 0;
68  }
69 
70  if ( input->GetNumberOfPoints() < 1 )
71  {
72  return 1;
73  }
74 
75  double bounds[6];
76  input->GetBounds( bounds );
77 
78  double pt[8][3];
79  int k = 0;
80  pt[k][0] = bounds[0];
81  pt[k][1] = bounds[2];
82  pt[k++][2] = bounds[4];
83 
84  pt[k][0] = bounds[1];
85  pt[k][1] = bounds[2];
86  pt[k++][2] = bounds[4];
87 
88  pt[k][0] = bounds[0];
89  pt[k][1] = bounds[3];
90  pt[k++][2] = bounds[4];
91 
92  pt[k][0] = bounds[0];
93  pt[k][1] = bounds[3];
94  pt[k++][2] = bounds[4];
95 
96  pt[k][0] = bounds[0];
97  pt[k][1] = bounds[2];
98  pt[k++][2] = bounds[5];
99 
100  pt[k][0] = bounds[1];
101  pt[k][1] = bounds[2];
102  pt[k++][2] = bounds[5];
103 
104  pt[k][0] = bounds[0];
105  pt[k][1] = bounds[3];
106  pt[k++][2] = bounds[5];
107 
108  pt[k][0] = bounds[1];
109  pt[k][1] = bounds[3];
110  pt[k++][2] = bounds[5];
111 
112  bool sign0 = ( this->CutFunction->FunctionValue( pt[0] ) > 0. );
113  bool intersect = false;
114 
115  for( unsigned int i = 1; ( i < 8 ) && ( !intersect ); i++ )
116  {
117  bool sign = ( this->CutFunction->FunctionValue( pt[i] ) >= 0. );
118  if( sign != sign0 )
119  {
120  intersect = true;
121  }
122  }
123 
124  if( intersect )
125  {
126  return vtkCutter::RequestData( request, inputVector, outputVector );
127  }
128  else
129  {
130  return 1;
131  }
132  }
133 
134 private:
136  void operator = (const vtkPlaneCutter&);
137 };
138 
140 #endif
141 
vtkPlaneCutter(vtkImplicitFunction *cf=NULL)
vtkTypeMacro(vtkPlaneCutter, vtkCutter)
static vtkPlaneCutter * New()
virtual int RequestData(vtkInformation *request, vtkInformationVector **inputVector, vtkInformationVector *outputVector)
void operator=(const vtkPlaneCutter &)
virtual ~vtkPlaneCutter()
vtkStandardNewMacro(vtkFillImageWithPolyData)