COPASI API  4.16.103
CLTransformation.cpp
Go to the documentation of this file.
2 // \$Source: /Volumes/Home/Users/shoops/cvs/copasi_dev/copasi/layout/CLTransformation.cpp,v \$
3 // \$Revision: 1.4 \$
4 // \$Name: \$
5 // \$Author: shoops \$
6 // \$Date: 2012/04/23 15:44:51 \$
8
9 // Copyright (C) 2012 - 2010 by Pedro Mendes, Virginia Tech Intellectual
10 // Properties, Inc., University of Heidelberg, and The University
11 // of Manchester.
13
14 #include <limits>
15 #include <string.h> // for memcmp
16
17 #include <sbml/packages/render/sbml/Transformation.h>
18
19 #include "CLTransformation.h"
20
23
24 /**
25  * Default constructor.
26  * All matrix elements are set to NaN
27  */
29 {
30  unsigned int i;
31
32  for (i = 0; i < 12; ++i)
33  {
34  mMatrix[i] = std::numeric_limits<double>::quiet_NaN();
35  }
36 }
37
38 /**
39  * Constructor with id and values for the matrix.
40  */
41 CLTransformation::CLTransformation(const double matrix[12]): CLBase()
42 {
43  unsigned int i;
44
45  for (i = 0; i < 12; ++i)
46  {
47  mMatrix[i] = matrix[i];
48  }
49 }
50
51 /**
52  * Sets the matrix.
53  */
54 void CLTransformation::setMatrix(const double m[12])
55 {
56  unsigned int i;
57
58  for (i = 0; i < 12; ++i)
59  {
60  mMatrix[i] = m[i];
61  }
62 }
63
64 /**
65  * Returns the matrix.
66  * The matrix contains 12 values.
67  */
68 const double* CLTransformation::getMatrix() const
69 {
70  return mMatrix;
71 }
72
73 /**
74  * Returns the 3D identity matrix.
75  * The matrix contains 12 values.
76  */
78 {
79  return IDENTITY3D;
80 }
81
82 const double CLTransformation::IDENTITY3D[12] = {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0};
83
84 /**
85  * Returns true if the matrix has been set or false otherwise.
86  */
88 {
89  bool result = true;
90  unsigned int i;
91
92  for (i = 0; result && i < 12; ++i)
93  {
94  result = (mMatrix[i] == mMatrix[i]);
95  }
96
97  return result;
98 }
99
100 /**
101  * Returns true if the matrix is the identity matrix.
102  */
104 {
105  return !memcmp(mMatrix, CLTransformation::IDENTITY3D, sizeof(double)*12);
106 }
107
108 /**
109  * Checks if the transformation is a 2D transformation, i.e.
110  * we have to check some of the values.
111  */
113 {
114  return mMatrix[2] == 0.0 &&
115  mMatrix[5] == 0.0 &&
116  mMatrix[6] == 0.0 &&
117  mMatrix[7] == 0.0 &&
118  mMatrix[8] == 1.0 &&
119  mMatrix[11] == 0.0;
120 }
121
122 /**
123  * Returns a string to represent the 3D transformation.
124  */
126 {
127  // transform the matrix to a string
128  std::ostringstream os;
129  unsigned int i;
130  os << mMatrix[0];
131
132  for (i = 1; i < 12; ++i)
133  {
134  os << "," << mMatrix[i];
135  }
136
137  return os.str();
138 }
139
140 /**
141  * Sets the transformation matrix from the given string.
142  * The string has to contain 12 numerical values seperated by ",".
143  * Otherwise the matrix is set to the identity matrix.
144  */
145 void CLTransformation::parseTransformation(const std::string& transformationString)
146 {
147  // the string should contain a list of 6 komma seperated numbers
148  // if it doesn't, we try to set the 3D matrix
149  bool result = true;
150  std::string delimiter = ",";
151  std::size_t lastPos = transformationString.find_first_not_of(delimiter);
152  std::size_t pos;
153  unsigned int index = 0;
154
155  while (lastPos != std::string::npos)
156  {
157  if (index > 11)
158  {
159  result = false;
160  break;
161  }
162
163  pos = transformationString.find_first_of(delimiter, lastPos);
164  double value = strtod(transformationString.substr(lastPos, pos - lastPos).c_str(), NULL);
165  mMatrix[index] = value;
166  index++;
167  lastPos = transformationString.find_first_not_of(delimiter, pos);
168  }
169
170  if (!result || index != 12)
171  {
173  }
174 }
std::string get3DTransformationString() const
void setMatrix(const double m[12])
bool is2DTransformation() const
static const double IDENTITY3D[12]
virtual void parseTransformation(const std::string &transformationString)
static const double * getIdentityMatrix()
Definition: CLBase.h:33
virtual const double * getMatrix() const
bool isSetMatrix() const
bool isIdentityMatrix() const