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 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
|
//##########################################################################
//# #
//# CLOUDCOMPARE #
//# #
//# This program is free software; you can redistribute it and/or modify #
//# it under the terms of the GNU General Public License as published by #
//# the Free Software Foundation; version 2 or later of the License. #
//# #
//# This program is distributed in the hope that it will be useful, #
//# but WITHOUT ANY WARRANTY; without even the implied warranty of #
//# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
//# GNU General Public License for more details. #
//# #
//# COPYRIGHT: EDF R&D / TELECOM ParisTech (ENST-TSI) #
//# #
//##########################################################################
#include "ccIndexedTransformation.h"
//Qt
#include <QFile>
#include <QTextStream>
//System
#include <assert.h>
#include <string>
ccIndexedTransformation::ccIndexedTransformation()
: ccGLMatrix()
, m_index(0)
{
}
ccIndexedTransformation::ccIndexedTransformation(const ccGLMatrix& matrix)
: ccGLMatrix(matrix)
, m_index(0)
{
}
ccIndexedTransformation::ccIndexedTransformation(const ccGLMatrix& matrix, double index)
: ccGLMatrix(matrix)
, m_index(index)
{
}
ccIndexedTransformation::ccIndexedTransformation(const ccIndexedTransformation& trans)
: ccGLMatrix(trans)
, m_index(trans.m_index)
{
}
bool ccIndexedTransformation::toAsciiFile(QString filename, int precision/*=12*/) const
{
QFile fp(filename);
if (!fp.open(QFile::WriteOnly | QFile::Text))
return false;
QTextStream stream(&fp);
stream.setRealNumberNotation(QTextStream::FixedNotation);
stream.setRealNumberPrecision(precision);
//save transformation first (so that it can be loaded as a ccGLMatrix!)
for (unsigned i=0; i<4; ++i)
{
stream << m_mat[i] << " " << m_mat[i+4] << " " << m_mat[i+8] << " " << m_mat[i+12] << endl;
}
//save index next
stream << m_index;
return (fp.error() == QFile::NoError);
}
bool ccIndexedTransformation::fromAsciiFile(QString filename)
{
QFile fp(filename);
if (!fp.open(QFile::ReadOnly | QFile::Text))
return false;
QTextStream stream(&fp);
//read the transformation first
for (unsigned i=0; i<4; ++i)
{
stream >> m_mat[i];
stream >> m_mat[i+4];
stream >> m_mat[i+8];
stream >> m_mat[i+12];
}
//read index
stream >> m_index;
return (fp.error() == QFile::NoError);
}
ccIndexedTransformation ccIndexedTransformation::operator * (const ccGLMatrix& M) const
{
return ccIndexedTransformation( *static_cast<const ccGLMatrix*>(this) * M, m_index);
}
ccIndexedTransformation& ccIndexedTransformation::operator *= (const ccGLMatrix& M)
{
ccGLMatrix temp = (*this) * M;
(*this) = temp;
return (*this);
}
//ccIndexedTransformation ccIndexedTransformation::operator * (const ccIndexedTransformation& trans) const
//{
// return ccIndexedTransformation( static_cast<ccGLMatrix*>(this) * trans, m_index);
//}
//
//ccIndexedTransformation& ccIndexedTransformation::operator *= (const ccIndexedTransformation& trans)
//{
// ccGLMatrix temp = (*this) * M;
// (*this) = temp;
//
// return (*this);
//}
ccIndexedTransformation& ccIndexedTransformation::operator += (const CCVector3& T)
{
*static_cast<ccGLMatrix*>(this) += T;
return (*this);
}
ccIndexedTransformation& ccIndexedTransformation::operator -= (const CCVector3& T)
{
*static_cast<ccGLMatrix*>(this) -= T;
return (*this);
}
ccIndexedTransformation ccIndexedTransformation::transposed() const
{
ccIndexedTransformation t(*this);
t.transpose();
return t;
}
ccIndexedTransformation ccIndexedTransformation::inverse() const
{
ccIndexedTransformation t(*this);
t.invert();
return t;
}
ccIndexedTransformation ccIndexedTransformation::Interpolate( double index,
const ccIndexedTransformation& trans1,
const ccIndexedTransformation& trans2)
{
double dt = trans2.getIndex() - trans1.getIndex();
if (dt == 0.0)
{
assert(index == trans1.getIndex());
return trans1;
}
//we compute the transformation matrix between trans1 and trans2
double t = (index - trans1.getIndex())/dt;
assert(t >= 0 && t <= 1);
ccGLMatrix mat = ccGLMatrix::Interpolate(static_cast<PointCoordinateType>(t),trans1,trans2);
return ccIndexedTransformation(mat, index);
}
bool ccIndexedTransformation::toFile(QFile& out) const
{
if (!ccGLMatrix::toFile(out))
return false;
assert(out.isOpen() && (out.openMode() & QIODevice::WriteOnly));
//index (dataVersion>=34)
if (out.write((const char*)&m_index,sizeof(double)) < 0)
return WriteError();
return true;
}
bool ccIndexedTransformation::fromFile(QFile& in, short dataVersion, int flags)
{
if (!ccGLMatrix::fromFile(in, dataVersion, flags))
return false;
assert(in.isOpen() && (in.openMode() & QIODevice::ReadOnly));
if (dataVersion<34)
return CorruptError();
//index (dataVersion>=34)
if (in.read((char*)&m_index,sizeof(double)) < 0)
return ReadError();
return true;
}
|