Skip to content

Commit 264a4c4

Browse files
author
Daniele Giunchi
committed
remove old matrix API, replace with OpenCV one
(CvMat)
1 parent 2295b25 commit 264a4c4

File tree

10 files changed

+98
-85
lines changed

10 files changed

+98
-85
lines changed

src/mafPluginVTK/mafDataBoundaryAlgorithmVTK.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ mafCore::mafProxyInterface *mafDataBoundaryAlgorithmVTK::calculateBoundary(doubl
6161
vtkMatrix4x4 *mat = vtkMatrix4x4::New();
6262
mat->Identity();
6363
for(int i=0;i<3;++i)
64-
mat->SetElement(i,0,matrix->get(i,0));
64+
mat->SetElement(i,0,cvmGet(matrix,i,0));
6565
for(int i=0;i<3;++i)
66-
mat->SetElement(i,1,matrix->get(i,1));
66+
mat->SetElement(i,1,cvmGet(matrix,i,1));
6767
for(int i=0;i<3;++i)
68-
mat->SetElement(i,2,matrix->get(i,2));
68+
mat->SetElement(i,2,cvmGet(matrix,i,2));
6969
for(int i=0;i<3;++i)
70-
mat->SetElement(i,3,matrix->get(i,3));
70+
mat->SetElement(i,3,cvmGet(matrix,i,3));
7171

7272
t->SetMatrix(mat);
7373
t->Update();

src/mafResources/mafDataSet.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ mafDataSet::mafDataSet(const QString code_location) : mafObject(code_location),
2626
mafDataSet::~mafDataSet() {
2727
// External data must be destroyed by the creator if no pointer to destructor function has been given.
2828
mafDEL(m_DataBoundaryAlgorithm);
29-
delete m_Matrix;
30-
m_Matrix = NULL;
29+
if(m_Matrix != NULL) {
30+
cvReleaseMat(&m_Matrix);
31+
}
3132
}
3233

3334
void mafDataSet::setBoundaryAlgorithm(mafDataBoundaryAlgorithm *algorithm) {
@@ -88,9 +89,10 @@ void mafDataSet::setPoseMatrix(const mafPoseMatrix *matrix) {
8889
return;
8990
}
9091
if(m_Matrix == NULL) {
91-
m_Matrix = new mafPoseMatrix();
92+
m_Matrix = cvCreateMat(4,4,CV_64FC1);
9293
}
93-
*m_Matrix = *matrix;
94+
95+
cvCopy(matrix, m_Matrix);
9496
setModified();
9597
}
9698

@@ -132,14 +134,14 @@ void mafDataSet::setMemento(mafMemento *memento, bool deep_memento) {
132134
foreach(item, *list) {
133135
if(item.m_Name == "poseMatrix") {
134136
//Restore the pose matrix
135-
mafPoseMatrix *mat = new mafPoseMatrix();
137+
mafPoseMatrix *mat = cvCreateMat(4,4,CV_64FC1);
136138
int counter = 0;
137139
int r = 0;
138140
for ( ; r < 4; ++r) {
139141
int c = 0;
140142
for ( ; c < 4 ; ++c) {
141143
double val = item.m_Value.toList()[counter].toDouble();
142-
mat->put(r,c,val);
144+
cvmSet(mat,r,c,val);
143145
++counter;
144146
}
145147
}

src/mafResources/mafDataSetCollection.cpp

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,13 @@ void mafDataSetCollection::orientations(double ori[3], double t) {
103103
double sx, sy;
104104

105105
// Extract the rotation sub-matrix and calculate the angles considering the Yaw-Pitch-Roll convention.
106-
nx = m->get(0,0);
107-
ny = m->get(1,0);
108-
nz = m->get(2,0);
109-
ax = m->get(0,2);
110-
ay = m->get(1,2);
111-
sx = m->get(0,1);
112-
sy = m->get(1,1);
106+
nx = cvmGet(m,0,0);
107+
ny = cvmGet(m,1,0);
108+
nz = cvmGet(m,2,0);
109+
ax = cvmGet(m,0,2);
110+
ay = cvmGet(m,1,2);
111+
sx = cvmGet(m,0,1);
112+
sy = cvmGet(m,1,1);
113113

114114
ori[Z_AXIS] = atan2(ny, nx);
115115
ori[Y_AXIS] = atan2(-nz, cos(ori[Z_AXIS])*nx + sin(ori[Z_AXIS])*ny);
@@ -143,7 +143,7 @@ void mafDataSetCollection::position(double pos[3], double t) {
143143

144144
// Extract the position vector from the matrix and write it into the array.
145145
for(int i = 0; i < 3; ++i) {
146-
pos[i] = m->get(i,3);
146+
pos[i] = cvmGet(m,i,3);
147147
}
148148
}
149149

@@ -170,51 +170,58 @@ mafPoseMatrix *mafDataSetCollection::poseMatrix(double t) {
170170

171171
void mafDataSetCollection::writePosition(double x, double y, double z, mafPoseMatrix *m) {
172172
// Write the position vector into the given matrix.
173-
m->put(0,3, x);
174-
m->put(1,3, y);
175-
m->put(2,3, z);
173+
cvmSet(m,0,3,x);
174+
cvmSet(m,1,3,y);
175+
cvmSet(m,2,3,z);
176176
}
177177

178178
void mafDataSetCollection::writeOrientation(double rx, double ry, double rz, mafPoseMatrix *m) {
179-
// calculate the rotation sub-matrix considering the Yaw-Pitch-Roll convention.
180-
mafPoseMatrix Rz;
181-
mafPoseMatrix Ry;
182-
mafPoseMatrix Rx;
183-
184-
Rz.set_identity();
185-
Ry.set_identity();
186-
Rx.set_identity();
179+
// calculate the rotation sub-matrix considering the Yaw-Pitch-Roll convention.
180+
mafPoseMatrix *Rz = cvCreateMat(4,4,CV_64FC1);
181+
cvSetIdentity(Rz);
182+
mafPoseMatrix *Ry = cvCreateMat(4,4,CV_64FC1);
183+
cvSetIdentity(Ry);
184+
mafPoseMatrix *Rx = cvCreateMat(4,4,CV_64FC1);
185+
cvSetIdentity(Rx);
187186

188187
double rx_rad, ry_rad, rz_rad;
189188
rx_rad = degreesToRadiant(rx);
190189
ry_rad = degreesToRadiant(ry);
191190
rz_rad = degreesToRadiant(rz);
192191

193-
Rz.put(0,0,cos(rz_rad));
194-
Rz.put(1,1,cos(rz_rad));
195-
Rz.put(0,1,-sin(rz_rad));
196-
Rz.put(1,0,sin(rz_rad));
192+
cvmSet(Rz,0,0,cos(rz_rad));
193+
cvmSet(Rz,1,1,cos(rz_rad));
194+
cvmSet(Rz,0,1,-sin(rz_rad));
195+
cvmSet(Rz,1,0,sin(rz_rad));
197196

198-
Ry.put(0,0,cos(ry_rad));
199-
Ry.put(2,2,cos(ry_rad));
200-
Ry.put(0,2,sin(ry_rad));
201-
Ry.put(2,0,-sin(ry_rad));
197+
cvmSet(Ry,0,0,cos(ry_rad));
198+
cvmSet(Ry,2,2,cos(ry_rad));
199+
cvmSet(Ry,0,2,sin(ry_rad));
200+
cvmSet(Ry,2,0,-sin(ry_rad));
202201

203-
Rx.put(1,1,cos(rx_rad));
204-
Rx.put(2,2,cos(rx_rad));
205-
Rx.put(1,2,-sin(rx_rad));
206-
Rx.put(2,1,sin(rx_rad));
202+
cvmSet(Rx,1,1,cos(rx_rad));
203+
cvmSet(Rx,2,2,cos(rx_rad));
204+
cvmSet(Rx,1,2,-sin(rx_rad));
205+
cvmSet(Rx,2,1,sin(rx_rad));
207206

208207
// Store the old position for the matrix m
209208
double pos[3];
210209
for(int i = 0; i < 3; ++i) {
211-
pos[i] = m->get(i,3);
210+
pos[i] = cvmGet(m,i,3);
212211
}
213212

214213
// Copy into 'm' the result of the matrix multiplication.
215-
*m = Rz * Ry * Rx;
214+
mafPoseMatrix *T = cvCreateMat(4,4,CV_64FC1);
215+
cvMatMul(Rz, Ry, T);
216+
cvMatMul(T, Rx, m);
216217
// Re-Apply the position
217218
writePosition(pos[0], pos[1], pos[2], m);
219+
cvReleaseMat(&Rx);
220+
cvReleaseMat(&Ry);
221+
cvReleaseMat(&Rz);
222+
cvReleaseMat(&T);
223+
224+
218225
}
219226

220227
bool mafDataSetCollection::insertItem(mafDataSet *item, double t) {
@@ -303,13 +310,12 @@ mafDataSet *mafDataSetCollection::itemAt(double t) {
303310
item = mafNEW(mafResources::mafDataSet);
304311
item->setParent(this);
305312
mafPoseMatrix *m;
306-
m = new mafPoseMatrix();
307-
m->set_identity();
313+
m = cvCreateMat(4,4,CV_64FC1);
314+
cvSetIdentity(m);
308315
item->setPoseMatrix(m);
309316
insertItem(item, ts);
310317
item->release();
311-
delete m;
312-
m = NULL;
318+
cvReleaseMat(&m);
313319
}
314320
return item;
315321
}

src/mafResources/mafMementoDataSet.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ mafMementoDataSet::mafMementoDataSet(const mafObject *obj, bool binary, const QS
3838
for ( ; r < 4; ++r) {
3939
int c = 0;
4040
for ( ; c < 4 ; ++c ) {
41-
matrixList.append(matrix->get(r, c));
41+
matrixList.append(cvmGet(matrix,r,c));
42+
4243
}
4344
}
4445
mafMementoPropertyItem item;

src/mafResources/mafResourcesDefinitions.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
#include <mafProxyInterface.h>
2929

3030

31-
// vnl includes
32-
#include <vnl/vnl_double_4x4.h>
33-
#include <vnl/vnl_vector_fixed.h>
31+
// OpenCV includes
32+
#include <cv.h>
3433

3534
namespace mafResources {
3635

@@ -40,7 +39,7 @@ class mafResource;
4039
class mafVME;
4140

4241
/// Type definition for MAF3 pose matrix.
43-
typedef vnl_double_4x4 mafPoseMatrix;
42+
typedef CvMat mafPoseMatrix;
4443

4544
/// Type definition for a list of mafResource.
4645
typedef QList<mafResource *> mafResourceList;

test/mafPluginVTKTest/mafDataBoundaryAlgorithmVTKTest.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ private slots:
6161
m_DataSourceContainer.setClassTypeNameFunction(vtkClassTypeNameExtract);
6262
m_DataSourceContainer = m_DataSource->GetOutputPort(0);
6363

64-
65-
mafPoseMatrix *newMatrix = new mafPoseMatrix();
66-
newMatrix->set_identity();
64+
mafPoseMatrix *newMatrix = cvCreateMat(4,4,CV_64FC1);
65+
cvSetIdentity(newMatrix);
6766

6867
m_DataSetCube = mafNEW(mafResources::mafDataSet);
6968
mafDataBoundaryAlgorithmVTK *boundaryAlgorithm;

test/mafResourcesTest/mafDataSetCollectionTest.cpp

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -130,31 +130,33 @@ void mafDataSetCollectionTest::collectionPoseMatrixTest() {
130130

131131
void mafDataSetCollectionTest::collectionInsertItemTest() {
132132
// Create a test matrix to add to the collection.
133-
mafPoseMatrix *new_matrix = new mafPoseMatrix();
134-
new_matrix->set_identity();
135-
new_matrix->put(0,3,5.0);
136-
new_matrix->put(1,3,2.3);
137-
new_matrix->put(2,3,4.1);
133+
mafPoseMatrix *newMatrix = cvCreateMat(4,4,CV_64FC1);
134+
cvSetIdentity(newMatrix);
135+
136+
cvmSet(newMatrix, 0, 3, 5.0);
137+
cvmSet(newMatrix, 1, 3, 1.3);
138+
cvmSet(newMatrix, 2, 3, 4.1);
138139

139140
mafDataSet *item = mafNEW(mafResources::mafDataSet);
140-
item->setPoseMatrix(new_matrix);
141+
item->setPoseMatrix(newMatrix);
141142

142143
// Insert a new pose matrix at the given timestamp.
143144
//! <snippet>
144145
bool result_insert = m_Collection->insertItem(item, 1.5);
145146
//! </snippet>
146-
147+
cv::Mat mat;
148+
147149
QVERIFY(result_insert);
148150

149151
//! <snippet>
150152
mafPoseMatrix *m = m_Collection->poseMatrix(1.5);
151153
//! </snippet>
152-
QVERIFY(*m == *new_matrix);
154+
155+
QVERIFY(cvmGet(m, 1,2) == cvmGet(newMatrix, 1,2));
153156

154157
mafDEL(item);
155158

156-
delete new_matrix;
157-
new_matrix = NULL;
159+
cvReleaseMat(&newMatrix);
158160
}
159161

160162
void mafDataSetCollectionTest::collectionDataSetTest() {
@@ -201,14 +203,15 @@ void mafDataSetCollectionTest::collectionDataSetTest() {
201203

202204
void mafDataSetCollectionTest::collectionRemoveItemTest() {
203205
// Create a test matrix to add to the collection.
204-
mafPoseMatrix *new_matrix = new mafPoseMatrix();
205-
new_matrix->set_identity();
206-
new_matrix->put(0,3,5.0);
207-
new_matrix->put(1,3,2.3);
208-
new_matrix->put(2,3,4.1);
206+
mafPoseMatrix *newMatrix = cvCreateMat(4,4,CV_64FC1);
207+
cvSetIdentity(newMatrix);
208+
209+
cvmSet(newMatrix, 0, 3, 5.0);
210+
cvmSet(newMatrix, 1, 3, 1.3);
211+
cvmSet(newMatrix, 2, 3, 4.1);
209212

210213
mafDataSet *item = mafNEW(mafResources::mafDataSet);
211-
item->setPoseMatrix(new_matrix);
214+
item->setPoseMatrix(newMatrix);
212215

213216
// Add a new item at a new timestamp.
214217
bool result_insert = m_Collection->insertItem(item, 3.5);

test/mafResourcesTest/mafMementoDataSetCollectionTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ void mafMementoDataSetCollectionTest::mafMementoDataSetCollectionAllocationTest(
9191
//Create dataset for the collection
9292
mafDataSet *firstData = mafNEW(mafResources::mafDataSet);
9393
mafDataSet *secondData = mafNEW(mafResources::mafDataSet);
94-
mafPoseMatrix *matrix = new mafPoseMatrix();
95-
matrix->set_identity();
96-
matrix->put(0,0,3);
94+
mafPoseMatrix *matrix = cvCreateMat(4,4,CV_64FC1);
95+
cvSetIdentity(matrix);
96+
cvmSet(matrix, 0,0,3);
9797
firstData->setPoseMatrix(matrix);
9898

9999
//Fill the mafDataSetCollection
@@ -109,7 +109,7 @@ void mafMementoDataSetCollectionTest::mafMementoDataSetCollectionAllocationTest(
109109
mafMemento *returnMemento = newCollection->createMemento();
110110
QVERIFY(memento->isEqual(returnMemento));
111111

112-
delete matrix;
112+
cvReleaseMat(&matrix);
113113
mafDEL(secondData);
114114
mafDEL(firstData);
115115
mafDEL(vme);

test/mafResourcesTest/mafMementoDataSetTest.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,10 @@ void mafMementoDataSetTest::mafMementoDataSetCustomAllocationTest() {
160160
container.setExternalCodecType("CUSTOM");
161161
m_DataSet->setDataValue(&container);
162162

163-
mafPoseMatrix *matrix = new mafPoseMatrix();
164-
matrix->set_identity();
165-
matrix->put(0,0,3);
163+
mafPoseMatrix *matrix = cvCreateMat(4,4,CV_64FC1);
164+
cvSetIdentity(matrix);
165+
cvmSet(matrix, 0,0,3);
166+
166167
m_DataSet->setPoseMatrix(matrix);
167168

168169
//Plug the codec
@@ -190,7 +191,7 @@ void mafMementoDataSetTest::mafMementoDataSetCustomAllocationTest() {
190191
mafMemento *returnMemento = returnDataSet->createMemento();
191192
QVERIFY(memento->isEqual(returnDataSet));
192193

193-
delete matrix;
194+
cvReleaseMat(&matrix);
194195
mafDEL(returnDataSet);
195196
mafDEL(returnMemento);
196197
mafDEL(memento);

test/mafResourcesTest/mafMementoVMETest.cpp

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,10 @@ void mafMementoVMETest::mafMementoVMECustomAllocationTest() {
197197
mafDataSet *dataSet = mafNEW(mafResources::mafDataSet);
198198
dataSet->setDataValue(&container);
199199

200-
mafPoseMatrix *matrix = new mafPoseMatrix();
201-
matrix->set_identity();
202-
matrix->put(0,0,3);
200+
mafPoseMatrix *matrix = cvCreateMat(4,4,CV_64FC1);
201+
cvSetIdentity(matrix);
202+
cvmSet(matrix, 0,0,3);
203+
203204
dataSet->setPoseMatrix(matrix);
204205

205206
//Create second dataSet
@@ -210,9 +211,10 @@ void mafMementoVMETest::mafMementoVMECustomAllocationTest() {
210211
mafDataSet *dataSet2 = mafNEW(mafResources::mafDataSet);
211212
dataSet2->setDataValue(&container2);
212213

213-
mafPoseMatrix *matrix2 = new mafPoseMatrix();
214-
matrix2->set_identity();
215-
matrix2->put(1,0,5);
214+
mafPoseMatrix *matrix2 = cvCreateMat(4,4,CV_64FC1);
215+
cvSetIdentity(matrix2);
216+
cvmSet(matrix2, 1,0,5);
217+
216218
dataSet2->setPoseMatrix(matrix2);
217219

218220
mafDataSetCollection *collection = m_VME->dataSetCollection();

0 commit comments

Comments
 (0)