OSDN Git Service

FIRST REPOSITORY
[eos/hostdependOTHERS.git] / HP / util / HP / include / vtk / vtkTensor.h
1 /*=========================================================================
2
3   Program:   Visualization Toolkit
4   Module:    $RCSfile: vtkTensor.h,v $
5   Language:  C++
6   Date:      $Date: 2002/02/01 06:33:15 $
7   Version:   $Revision: 1.1.1.1 $
8
9
10 Copyright (c) 1993-1998 Ken Martin, Will Schroeder, Bill Lorensen.
11
12 This software is copyrighted by Ken Martin, Will Schroeder and Bill Lorensen.
13 The following terms apply to all files associated with the software unless
14 explicitly disclaimed in individual files. This copyright specifically does
15 not apply to the related textbook "The Visualization Toolkit" ISBN
16 013199837-4 published by Prentice Hall which is covered by its own copyright.
17
18 The authors hereby grant permission to use, copy, and distribute this
19 software and its documentation for any purpose, provided that existing
20 copyright notices are retained in all copies and that this notice is included
21 verbatim in any distributions. Additionally, the authors grant permission to
22 modify this software and its documentation for any purpose, provided that
23 such modifications are not distributed without the explicit consent of the
24 authors and that existing copyright notices are retained in all copies. Some
25 of the algorithms implemented by this software are patented, observe all
26 applicable patent law.
27
28 IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
29 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
30 OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, OR ANY DERIVATIVES THEREOF,
31 EVEN IF THE AUTHORS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, INCLUDING,
34 BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
35 PARTICULAR PURPOSE, AND NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN
36 "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
37 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
38
39
40 =========================================================================*/
41 // .NAME vtkTensor - supporting class to enable assignment and referencing of tensors
42 // .SECTION Description
43 // vtkTensor is a floating point representation of an nxn tensor. vtkTensor 
44 // provides methods for assignment and reference of tensor components. It 
45 // does it in such a way as to minimize data copying.
46 // .SECTION Caveats
47 // vtkTensor performs its operations using pointer reference. You are 
48 // responsible for supplying data storage (if necessary) if local copies 
49 // of data are being made.
50
51 #ifndef __vtkTensor_h
52 #define __vtkTensor_h
53
54 #include "vtkWin32Header.h"
55
56 class VTK_EXPORT vtkTensor
57 {
58 public:
59   vtkTensor();
60   void Delete() {delete this;};
61   static vtkTensor *New() {return new vtkTensor;};
62   void Initialize();
63   float GetComponent(int i, int j);
64   void SetComponent(int i, int j, float v);
65   void AddComponent(int i, int j, float v);
66   float *GetColumn(int j);
67   void DeepCopy(vtkTensor &t);
68   operator float*() {return this->T;};
69   float *T;
70
71 protected: 
72   float Storage[9];
73 };
74
75 // Initialize tensor components to 0.0.
76 inline void vtkTensor::Initialize()
77 {
78   for (int j=0; j<3; j++)
79     for (int i=0; i<3; i++)
80       this->T[i+j*3] = 0.0;
81 }
82
83 // Description:
84 // Get the tensor component (i,j).
85 inline float vtkTensor::GetComponent(int i, int j)
86 {
87   return this->T[i+3*j];
88 }
89
90 // Description:
91 // Set the value of the tensor component (i,j).
92 inline void vtkTensor::SetComponent(int i, int j, float v)
93 {
94   this->T[i+3*j] = v;
95 }
96
97 // Description:
98 // Add to the value of the tensor component at location (i,j).
99 inline void vtkTensor::AddComponent(int i, int j, float v)
100 {
101   this->T[i+3*j] += v;
102 }
103
104 // Description:
105 // Return column vector from tensor. (Assumes 2D matrix form and 0-offset.)
106 inline float *vtkTensor::GetColumn(int j)
107 {
108   return this->T + 3*j;
109 }
110
111 // Description:
112 // Deep copy of one tensor to another tensor.
113 inline void vtkTensor::DeepCopy(vtkTensor &t)
114 {
115   for (int j=0; j < 3; j++)
116     for (int i=0; i < 3; i++)
117       this->T[i+3*j] = t.T[i+3*j];
118 }
119
120 #endif