|
4 | 4 | #include <Qt3DRender/QBuffer> |
5 | 5 | #include <Qt3DExtras/QPhongAlphaMaterial> |
6 | 6 |
|
7 | | -#include <aliceVision/sfmDataIO/AlembicImporter.cpp> |
| 7 | +#include <aliceVision/sfmDataIO/sfmDataIO.hpp> |
8 | 8 |
|
9 | 9 | using namespace Qt3DRender; |
10 | 10 | using namespace aliceVision; |
@@ -55,14 +55,14 @@ ObservationsEntity::ObservationsEntity(std::string source, Qt3DCore::QNode* pare |
55 | 55 | fillLandmarksPerViews(); |
56 | 56 | } |
57 | 57 |
|
58 | | -void ObservationsEntity::setData(const Alembic::Abc::IObject& iObj) |
| 58 | +void ObservationsEntity::setData() |
59 | 59 | { |
60 | 60 | // contains the 3D coordinates of vertices in space in the following order: |
61 | 61 | // - the landmarks |
62 | 62 | // - the view cameras |
63 | 63 | QByteArray positionData; |
64 | 64 |
|
65 | | - fillBytesData(iObj, positionData); |
| 65 | + fillBytesData(positionData); |
66 | 66 |
|
67 | 67 | // contains the connections between the selected view and its corresponding |
68 | 68 | // observed landmarks |
@@ -152,64 +152,64 @@ void ObservationsEntity::fillLandmarksPerViews() |
152 | 152 | } |
153 | 153 | } |
154 | 154 |
|
155 | | -void ObservationsEntity::fillBytesData(const Alembic::Abc::IObject& iObj, QByteArray& positionData) |
| 155 | +void ObservationsEntity::fillBytesData(QByteArray& positionData) |
156 | 156 | { |
157 | | - using namespace Alembic::Abc; |
158 | | - using namespace Alembic::AbcGeom; |
159 | | - using sfmDataIO::AV_UInt32ArraySamplePtr; |
160 | | - |
161 | | - IPoints points(iObj, kWrapExisting); |
162 | | - IPointsSchema schema = points.getSchema(); |
163 | | - |
164 | 157 | // -------------- read position data ---------------------- |
165 | 158 |
|
166 | | - P3fArraySamplePtr positionsLandmarks = schema.getValue().getPositions(); |
167 | | - const auto& nLandmarks = positionsLandmarks->size(); |
| 159 | + const auto& nLandmarks = _sfmData.getLandmarks().size(); |
168 | 160 | const auto& nViews = _sfmData.getViews().size(); |
169 | 161 | positionData.resize(static_cast<int>((nLandmarks + nViews) * 3 * sizeof(float))); |
| 162 | + size_t nObservations = 0; |
170 | 163 | // copy positions of landmarks |
171 | | - memcpy(positionData.data(), (const char*)positionsLandmarks->get(), nLandmarks * 3 * sizeof(float)); |
| 164 | + { |
| 165 | + auto* positionsIt = positionData.data(); |
| 166 | + for (const auto& landIt : _sfmData.getLandmarks()) |
| 167 | + { |
| 168 | + aliceVision::Vec3f x = landIt.second.X.cast<float>(); |
| 169 | + // graphics to open-gl coordinates system |
| 170 | + x.z() *= -1; |
| 171 | + x.y() *= -1; |
| 172 | + memcpy(positionsIt, reinterpret_cast<char*>(x.data()), 3 * sizeof(float)); |
| 173 | + positionsIt += 3 * sizeof(float); |
| 174 | + nObservations += landIt.second.observations.size(); |
| 175 | + } |
| 176 | + } |
172 | 177 | // copy positions of view cameras and construct _viewId2vertexPos |
173 | 178 | { |
174 | | - auto* positionsIt = positionData.data(); |
175 | | - uint viewPosIdx = static_cast<uint>(nLandmarks); |
176 | | - // view camera positions are added after landmarks' |
177 | | - positionsIt += 3 * sizeof(float) * nLandmarks; |
178 | | - for (const auto& viewIt : _sfmData.getViews()) |
179 | | - { |
| 179 | + auto* positionsIt = positionData.data(); |
| 180 | + uint viewPosIdx = static_cast<uint>(nLandmarks); |
| 181 | + // view camera positions are added after landmarks' |
| 182 | + positionsIt += 3 * sizeof(float) * nLandmarks; |
| 183 | + for (const auto& viewIt : _sfmData.getViews()) |
| 184 | + { |
180 | 185 | _viewId2vertexPos[viewIt.first] = viewPosIdx++; |
181 | 186 | aliceVision::Vec3f center = _sfmData.getPose(*viewIt.second).getTransform().center().cast<float>(); |
182 | 187 | // graphics to open-gl coordinates system |
183 | 188 | center.z() *= -1; |
184 | 189 | center.y() *= -1; |
185 | 190 | memcpy(positionsIt, reinterpret_cast<char*>(center.data()), 3 * sizeof(float)); |
186 | 191 | positionsIt += 3 * sizeof(float); |
187 | | - } |
| 192 | + } |
188 | 193 | } |
189 | 194 |
|
190 | 195 | // -------------- read Tc index data ---------------------- |
191 | 196 |
|
192 | 197 | { |
193 | | - ICompoundProperty userProps = aliceVision::sfmDataIO::getAbcUserProperties(schema); |
194 | | - AV_UInt32ArraySamplePtr sampleVisibilitySize(userProps, "mvg_visibilitySize"); |
195 | | - AV_UInt32ArraySamplePtr sampleVisibilityViewId(userProps, "mvg_visibilityViewId"); |
196 | | - |
197 | | - _indexBytesByLandmark.resize(static_cast<int>(2 * sizeof(uint) * sampleVisibilityViewId.size())); |
198 | | - _landmarkId2IndexRange.resize(sampleVisibilityViewId.size()); |
| 198 | + _indexBytesByLandmark.resize(static_cast<int>(2 * sizeof(uint) * nObservations)); |
| 199 | + _landmarkId2IndexRange.resize(nLandmarks); |
199 | 200 | uint* indices = reinterpret_cast<uint*>(_indexBytesByLandmark.data()); |
200 | 201 | uint offset = 0; |
201 | 202 | size_t obsGlobalIndex = 0; |
202 | | - for (uint point3d_i = 0; point3d_i < sampleVisibilitySize.size(); ++point3d_i) |
| 203 | + for (const auto& landIt : _sfmData.getLandmarks()) |
203 | 204 | { |
204 | | - // Number of observation for this 3d point |
205 | | - const size_t visibilitySize = sampleVisibilitySize[point3d_i]; |
206 | | - const auto& delta = static_cast<uint>(visibilitySize * 2); |
207 | | - _landmarkId2IndexRange[point3d_i] = std::pair<uint, uint>(offset, delta); |
| 205 | + const auto& delta = static_cast<uint>(landIt.second.observations.size() * 2); |
| 206 | + _landmarkId2IndexRange[landIt.first] = std::pair<uint, uint>(offset, delta); |
208 | 207 | offset += delta; |
209 | | - for (size_t obs_i = 0; obs_i < visibilitySize; ++obs_i, ++obsGlobalIndex) |
| 208 | + for (const auto& obsIt : landIt.second.observations) |
210 | 209 | { |
211 | | - *indices++ = point3d_i; |
212 | | - *indices++ = _viewId2vertexPos.at(static_cast<IndexT>(sampleVisibilityViewId[obsGlobalIndex])); |
| 210 | + *indices++ = landIt.first; |
| 211 | + *indices++ = _viewId2vertexPos.at(obsIt.first); |
| 212 | + ++obsGlobalIndex; |
213 | 213 | } |
214 | 214 | } |
215 | 215 | } |
|
0 commit comments