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 201 202 203 204 205 206 207
|
//##########################################################################
//# #
//# 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 "ccSensor.h"
ccSensor::ccSensor(QString name)
: ccHObject(name)
, m_posBuffer(0)
, m_activeIndex(0)
, m_color(ccColor::green)
, m_scale(PC_ONE)
{
m_rigidTransformation.toIdentity();
}
ccSensor::ccSensor(const ccSensor &sensor)
: ccHObject(sensor)
, m_posBuffer(0)
, m_rigidTransformation(sensor.m_rigidTransformation)
, m_activeIndex(sensor.m_activeIndex)
, m_color(sensor.m_color)
, m_scale(sensor.m_scale)
{
if (sensor.m_posBuffer)
m_posBuffer = new ccIndexedTransformationBuffer(*sensor.m_posBuffer);
}
bool ccSensor::addPosition(ccGLMatrix& trans, double index)
{
if (!m_posBuffer)
{
m_posBuffer = new ccIndexedTransformationBuffer();
addChild(m_posBuffer);
m_posBuffer->setDisplay(getDisplay());
m_posBuffer->setVisible(true);
m_posBuffer->setEnabled(false);
}
bool sort = (!m_posBuffer->empty() && m_posBuffer->back().getIndex() > index);
try
{
m_posBuffer->emplace_back(trans,index);
}
catch (const std::bad_alloc&)
{
//not enough memory!
return false;
}
if (sort)
m_posBuffer->sort();
return true;
}
void ccSensor::applyGLTransformation(const ccGLMatrix& trans)
{
//transparent call
ccHObject::applyGLTransformation(trans);
//we update the rigid transformation
m_rigidTransformation = trans * m_rigidTransformation;
}
void ccSensor::getIndexBounds(double& minIndex, double& maxIndex) const
{
if (m_posBuffer && !m_posBuffer->empty())
{
minIndex = m_posBuffer->front().getIndex();
maxIndex = m_posBuffer->back().getIndex();
}
else
{
minIndex = maxIndex = 0;
}
}
bool ccSensor::getAbsoluteTransformation(ccIndexedTransformation& trans, double index) const
{
trans.toIdentity();
if (m_posBuffer)
if (!m_posBuffer->getInterpolatedTransformation(index,trans))
return false;
trans *= m_rigidTransformation;
return true;
}
bool ccSensor::getActiveAbsoluteTransformation(ccIndexedTransformation& trans) const
{
if (!getAbsoluteTransformation(trans, m_activeIndex))
{
ccLog::Warning("[ccSensor::getActiveAbsoluteTransformation] Failed to get a valid transformation for active index!");
return false;
}
return true;
}
bool ccSensor::getActiveAbsoluteCenter(CCVector3& vec) const
{
ccIndexedTransformation trans;
if (!getActiveAbsoluteTransformation(trans))
return false;
vec = trans.getTranslationAsVec3D();
return true;
}
bool ccSensor::getActiveAbsoluteRotation(ccGLMatrix& rotation) const
{
ccIndexedTransformation trans;
if (!getActiveAbsoluteTransformation(trans))
return false;
ccGLMatrix mat = trans;
mat.setTranslation(CCVector3(0.0,0.0,0.0));
rotation = mat;
return true;
}
bool ccSensor::toFile_MeOnly(QFile& out) const
{
if (!ccHObject::toFile_MeOnly(out))
return false;
//rigid transformation (dataVersion>=34)
if (!m_rigidTransformation.toFile(out))
return WriteError();
//various parameters (dataVersion>=35)
QDataStream outStream(&out);
outStream << m_activeIndex; //active index
outStream << m_scale; //scale
//color (dataVersion>=35)
if (out.write((const char*)&m_color.rgb,sizeof(ColorCompType)*3) < 0)
return WriteError();
//we can't save the associated position buffer (as it may be shared by multiple sensors)
//so instead we save it's unique ID (dataVersion>=34)
//WARNING: the buffer must be saved in the same BIN file! (responsibility of the caller)
uint32_t bufferUniqueID = (m_posBuffer ? (uint32_t)m_posBuffer->getUniqueID() : 0);
if (out.write((const char*)&bufferUniqueID,4) < 0)
return WriteError();
return true;
}
bool ccSensor::fromFile_MeOnly(QFile& in, short dataVersion, int flags)
{
if (!ccHObject::fromFile_MeOnly(in, dataVersion, flags))
return false;
//serialization wasn't possible before v3.4!
if (dataVersion < 34)
return false;
//rigid transformation (dataVersion>=34)
if (!m_rigidTransformation.fromFile(in,dataVersion,flags))
return ReadError();
//various parameters (dataVersion>=35)
QDataStream inStream(&in);
inStream >> m_activeIndex;
ccSerializationHelper::CoordsFromDataStream(inStream,flags,&m_scale);
//color (dataVersion>=35)
if (in.read((char*)&m_color.rgb,sizeof(ColorCompType)*3) < 0)
return ReadError();
//as the associated position buffer can't be saved directly (as it may be shared by multiple sensors)
//we only store its unique ID (dataVersion>=34) --> we hope we will find it at loading time (i.e. this
//is the responsibility of the caller to make sure that all dependencies are saved together)
uint32_t bufferUniqueID = 0;
if (in.read((char*)&bufferUniqueID,4) < 0)
return ReadError();
//[DIRTY] WARNING: temporarily, we set the vertices unique ID in the 'm_posBuffer' pointer!!!
*(uint32_t*)(&m_posBuffer) = bufferUniqueID;
return true;
}
bool ccSensor::applyViewport(ccGenericGLDisplay* win/*=0*/)
{
//not supported by default, must be reimplemented by the child class
ccLog::Warning("[ccSensor::applyViewport] Unhandled sensor type!");
return false;
}
|