Skip to content

Commit

Permalink
E57 importer
Browse files Browse the repository at this point in the history
  • Loading branch information
servantftechnicolor committed Jan 26, 2024
1 parent d8a43d3 commit 3cbc71b
Show file tree
Hide file tree
Showing 6 changed files with 623 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ if(ALICEVISION_BUILD_SFM)
endif()
endif()

if(ALICEVISION_BUILD_SFM)
find_package(E57Format)
endif()

# ==============================================================================
# CoinUtils, Clp, Osi
# ==============================================================================
Expand Down
9 changes: 9 additions & 0 deletions src/aliceVision/dataio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ if(ALICEVISION_HAVE_OPENCV)
list(APPEND dataio_files_sources VideoFeed.cpp)
endif()

if(TARGET E57Format)
list(APPEND dataio_files_headers E57Reader.hpp)
list(APPEND dataio_files_sources E57Reader.cpp)
endif()

alicevision_add_library(aliceVision_dataio
SOURCES ${dataio_files_headers} ${dataio_files_sources}
PUBLIC_LINKS
Expand All @@ -34,3 +39,7 @@ alicevision_add_library(aliceVision_dataio
if(ALICEVISION_HAVE_OPENCV)
target_link_libraries(aliceVision_dataio PRIVATE ${OpenCV_LIBS})
endif()

if (TARGET E57Format)
target_link_libraries(aliceVision_dataio PRIVATE E57Format)
endif()
14 changes: 14 additions & 0 deletions src/aliceVision/dataio/E57Reader.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// This file is part of the AliceVision project.
// Copyright (c) 2024 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#include "E57Reader.hpp"

namespace aliceVision {
namespace dataio {


} // namespace dataio
} // namespace aliceVision
280 changes: 280 additions & 0 deletions src/aliceVision/dataio/E57Reader.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,280 @@
// This file is part of the AliceVision project.
// Copyright (c) 2024 AliceVision contributors.
// This Source Code Form is subject to the terms of the Mozilla Public License,
// v. 2.0. If a copy of the MPL was not distributed with this file,
// You can obtain one at https://mozilla.org/MPL/2.0/.

#pragma once

#include <aliceVision/system/Logger.hpp>

#include <Eigen/Dense>

#include <E57SimpleData.h>
#include <E57SimpleReader.h>

namespace aliceVision {
namespace dataio {

class E57Reader
{
public:
struct PointInfo
{
unsigned short idMesh;
Eigen::Vector3d coords;
float intensity;
};

public:
E57Reader(const std::vector<std::string> & paths)
:
_paths(paths),
_idPath(-1),
_idMesh(-1),
_countMeshesForFile(0)
{

}

void reset()
{
_idPath = -1;
_idMesh = -1;
_countMeshesForFile = 0;
}

bool getNext(Eigen::Vector3d & sensorPosition, std::vector<PointInfo> & vertices, Eigen::Matrix<size_t, -1, -1> & grid)
{
//Go to next mesh of current file
_idMesh++;

//Load next file if needed
if (_idMesh >= _countMeshesForFile)
{
_idPath++;
_idMesh = 0;
if (_idPath >= _paths.size())
{
return false;
}

//Create reader
_reader = std::make_unique<e57::Reader>(_paths[_idPath], e57::ReaderOptions());
if (!_reader->IsOpen())
{
return false;
}

e57::E57Root root;
if (!_reader->GetE57Root(root))
{
return false;
}

//Compute number of meshes in file
_countMeshesForFile = _reader->GetData3DCount();
}

if (_idMesh >= _countMeshesForFile)
{
return false;
}

if (!_reader)
{
return false;
}

//Get header
e57::Data3D scanHeader;
if (!_reader->ReadData3D(_idMesh, scanHeader))
{
ALICEVISION_LOG_ERROR("Error reading mesh #" << _idMesh);
return false;
}

//Get sensor pose (worldTsensor)
Eigen::Quaternion<double> q(scanHeader.pose.rotation.w,
scanHeader.pose.rotation.x,
scanHeader.pose.rotation.y,
scanHeader.pose.rotation.z);

Eigen::Matrix3d R = q.normalized().toRotationMatrix();

Eigen::Vector3d t;
t(0) = scanHeader.pose.translation.x;
t(1) = scanHeader.pose.translation.y;
t(2) = scanHeader.pose.translation.z;

int64_t maxRows = 0;
int64_t maxColumns = 0;
int64_t countPoints = 0;
int64_t countGroups = 0;
int64_t maxGroupSize = 0;
bool isColumnIndex;

if (!_reader->GetData3DSizes(0, maxRows, maxColumns, countPoints, countGroups, maxGroupSize, isColumnIndex))
{
ALICEVISION_LOG_ERROR("Error reading content of mesh #" << _idMesh);
return false;
}

e57::Data3DPointsFloat data3DPoints(scanHeader);
e57::CompressedVectorReader datareader = _reader->SetUpData3DPointsData(_idMesh, countPoints, data3DPoints);

//Prepare list of vertices
vertices.clear();
vertices.reserve(countPoints);

//Prepare structured grid for sensor
grid.resize(maxRows, maxColumns);
grid.fill(std::numeric_limits<size_t>::max());

unsigned readCount = 0;
while ((readCount = datareader.read()) > 0)
{
//Check input compatibility
if (data3DPoints.sphericalRange != nullptr)
{
ALICEVISION_LOG_ERROR("Data contains spherical coordinates, this is not currently supported");
continue;
}

if (data3DPoints.cartesianX == nullptr)
{
ALICEVISION_LOG_ERROR("Data contains no cartesian coordinates");
continue;
}

if (data3DPoints.columnIndex == nullptr)
{
ALICEVISION_LOG_ERROR("Data contains no 2d column coordinates");
continue;
}

if (data3DPoints.rowIndex == nullptr)
{
ALICEVISION_LOG_ERROR("Data contains no 2d row coordinates");
continue;
}

if (data3DPoints.intensity == nullptr)
{
ALICEVISION_LOG_ERROR("Data contains no intensities");
continue;
}


for (int pos = 0; pos < readCount; pos++)
{
if (data3DPoints.cartesianInvalidState[pos])
{
continue;
}

Eigen::Vector3d pt;
pt(0) = data3DPoints.cartesianX[pos];
pt(1) = data3DPoints.cartesianY[pos];
pt(2) = data3DPoints.cartesianZ[pos];

//Transform point in the world frame
PointInfo pi;
pi.coords = (R * pt + t);
pi.idMesh = _idMesh;
pi.intensity = data3DPoints.intensity[pos],

grid(data3DPoints.rowIndex[pos], data3DPoints.columnIndex[pos]) = vertices.size();
vertices.push_back(pi);
}
}

sensorPosition = t;

return true;
}

Check notice on line 196 in src/aliceVision/dataio/E57Reader.hpp

View check run for this annotation

codefactor.io / CodeFactor

src/aliceVision/dataio/E57Reader.hpp#L47-L196

Complex Method
bool getNext(Eigen::Vector3d & sensorPosition)
{
//Go to next mesh of current file
_idMesh++;

//Load next file if needed
if (_idMesh >= _countMeshesForFile)
{
_idPath++;
_idMesh = 0;
if (_idPath >= _paths.size())
{
return false;
}

//Create reader
_reader = std::make_unique<e57::Reader>(_paths[_idPath], e57::ReaderOptions());
if (!_reader->IsOpen())
{
return false;
}

e57::E57Root root;
if (!_reader->GetE57Root(root))
{
return false;
}

//Compute number of meshes in file
_countMeshesForFile = _reader->GetData3DCount();
}

if (_idMesh >= _countMeshesForFile)
{
return false;
}

if (!_reader)
{
return false;
}

//Get header
e57::Data3D scanHeader;
if (!_reader->ReadData3D(_idMesh, scanHeader))
{
ALICEVISION_LOG_ERROR("Error reading mesh #" << _idMesh);
return false;
}

//Get sensor pose (worldTsensor)
Eigen::Quaternion<double> q(scanHeader.pose.rotation.w,
scanHeader.pose.rotation.x,
scanHeader.pose.rotation.y,
scanHeader.pose.rotation.z);

Eigen::Matrix3d R = q.normalized().toRotationMatrix();

Eigen::Vector3d t;
t(0) = scanHeader.pose.translation.x;
t(1) = scanHeader.pose.translation.y;
t(2) = scanHeader.pose.translation.z;

sensorPosition = t;

return true;
}

int getIdMesh()
{
return _idMesh;
}

private:
std::vector<std::string> _paths;
std::unique_ptr<e57::Reader> _reader;

int _idPath;
int _idMesh;
size_t _countMeshesForFile;
};

} // namespace dataio
} // namespace aliceVision
19 changes: 18 additions & 1 deletion src/software/convert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ if(ALICEVISION_BUILD_SFM)
Boost::boost
Boost::timer
)

if (TARGET E57Format)
alicevision_add_software(aliceVision_importe57
SOURCE main_importe57.cpp
FOLDER ${FOLDER_SOFTWARE_CONVERT}
LINKS aliceVision_system
aliceVision_cmdline
aliceVision_feature
aliceVision_sfmData
aliceVision_sfmDataIO
aliceVision_mesh
Boost::program_options
Boost::system
E57Format
nanoflann
)
endif()
endif() # ALICEVISION_BUILD_SFM


Expand All @@ -44,4 +61,4 @@ if(ALICEVISION_BUILD_MVS)
aliceVision_mesh
${Boost_LIBRARIES}
)
endif() # ALICEVISION_BUILD_MVS
endif() # ALICEVISION_BUILD_MVS
Loading

0 comments on commit 3cbc71b

Please sign in to comment.