Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • lwisyh/velodyneplugin
  • LidarView/velodyneplugin
  • wine1998/velodyneplugin
3 results
Show changes
Commits on Source (1)
Showing
with 830 additions and 0 deletions
---
# This configuration requires clang-format 3.8 or higher.
BasedOnStyle: Mozilla
AlignAfterOpenBracket: DontAlign
AlignOperands: false
AlwaysBreakAfterReturnType: None
AlwaysBreakAfterDefinitionReturnType: None
BreakBeforeBraces: Allman
ColumnLimit: 100
Standard: Cpp03
BinPackArguments: true
BinPackParameters: true
\ No newline at end of file
*.patch -text
*.pdf binary
*.h format.clang-format
*.cxx format.clang-format
Plugin/VelodyneLidar/Testing/Data/** filter=lfs diff=lfs merge=lfs -text
# Compiled source #
###################
*.com
*.class
*.dll
*.exe
*.o
*.so
*.pyc
build/
# IDE #
#######
*.user
*.config
*.creator
*.files
*.includes
# Packages #
############
# it's better to unpack these files and commit the raw source
# git has its own built in compression methods
*.7z
*.dmg
*.gz
*.iso
*.jar
*.rar
*.tar
*.zip
# Logs and databases #
######################
*.log
*.sql
*.sqlite
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db
# Others #
######################
.*~
/Documentation/html
# launch lidarview CI, see https://docs.gitlab.com/ee/ci/multi_project_pipelines.html
launch_lidarview_CI:
variables:
TRIGGER_MODULE_SHA: $CI_COMMIT_SHA
TRIGGER_MODULE_PATH: Plugins/VelodynePlugin
TRIGGER_MODULE_REMOTE_NAME: velodyneplugin-private
TRIGGER_MODULE_REPOSITORY_PATH: gitlab.kitware.com/LidarView/velodyneplugin-private.git
only:
- master
- merge_requests
- tags
trigger:
project: lidarview/VeloView-Velodyne
branch: master
strategy: depend
cmake_minimum_required(VERSION 3.18)
project(VelodynePlugin C CXX)
set(BUILD_SHARED_LIBS ON)
paraview_plugin_scan(
PLUGIN_FILES "${CMAKE_CURRENT_LIST_DIR}/Plugin/paraview.plugin"
ENABLE_BY_DEFAULT ON #You can use this instead of the variables above
PROVIDES_PLUGINS plugins
REQUIRES_MODULES required_modules)
foreach (module IN LISTS required_modules)
if (NOT TARGET "${module}")
message(FATAL_ERROR "VelodynePlugin missing required module ${module}")
endif ()
endforeach ()
paraview_plugin_build(
HEADERS_DESTINATION "${LV_INSTALL_INCLUDE_DIR}"
RUNTIME_DESTINATION "${LV_INSTALL_RUNTIME_DIR}"
LIBRARY_DESTINATION "${LV_INSTALL_LIBRARY_DIR}"
LIBRARY_SUBDIRECTORY "${LV_PLUGIN_BUILD_SUBDIRECTORY}"
PLUGINS_FILE_NAME "lidarview.VelodynePlugin.xml"
PLUGINS ${plugins}
AUTOLOAD VelodynePlugin
)
# Create Plugin
paraview_add_plugin(VelodynePlugin
VERSION "1.0"
MODULES VelodyneLidar
MODULE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/VelodyneLidar/vtk.module"
MODULE_ARGS
LICENSE_DESTINATION "${LV_INSTALL_INCLUDE_DIR}" #wip Temporary fix
TEST_DIRECTORY_NAME "NONE" # Do not let vtk_module build the default 'Testing' subdir, it complexifies paths
)
#-----------------------------------------------------------------------------
# Build Velodyne Plugin
#-----------------------------------------------------------------------------
# Every PacketInterpreter found in the sources are added to the compilation (lidar, HDLPosition, ...)
# This allow to compile private interpreter (that not appear in the public repository)
# without changing the cmakelist in the private repository
file(GLOB_RECURSE velodyneInterpreter_xml ${CMAKE_CURRENT_SOURCE_DIR}/*PacketInterpreter*.xml)
file(GLOB_RECURSE velodyneInterpreter_cxx ${CMAKE_CURRENT_SOURCE_DIR}/*PacketInterpreter*.cxx)
file(GLOB_RECURSE velodyneInterpreter_h ${CMAKE_CURRENT_SOURCE_DIR}/*PacketInterpreter*.h)
set(velodyneplugin_xml
${velodyneInterpreter_xml}
${CMAKE_CURRENT_SOURCE_DIR}/PlaneFitter/PlaneFitter.xml
)
set(velodyneplugin_sources
${velodyneInterpreter_cxx}
${CMAKE_CURRENT_SOURCE_DIR}/VelodynePacketInterpreter/vtkRollingDataAccumulator.cxx
${CMAKE_CURRENT_SOURCE_DIR}/VelodynePacketInterpreter/vtkVelodyneAdvancedPacketFraming.cxx
${CMAKE_CURRENT_SOURCE_DIR}/VelodynePacketInterpreter/RpmCalculator.cxx
)
set(velodyneplugin_headers
${velodyneInterpreter_h}
)
set(velodyneplugin_classes
${CMAKE_CURRENT_SOURCE_DIR}/PlaneFitter/vtkPlaneFitter
)
set(plugin_include_dirs
${CMAKE_CURRENT_SOURCE_DIR}/PlaneFitter/
${CMAKE_CURRENT_SOURCE_DIR}/VelodynePacketInterpreter/
${CMAKE_CURRENT_SOURCE_DIR}/VelodyneHDLPositionPacketInterpreter/
)
# Create Module
vtk_module_add_module(VelodyneLidar
FORCE_STATIC # Using FORCE_STATIC build the vtk module statically into the plugin library, to avoid confusion when loading
SOURCES ${velodyneplugin_sources} # Will not trigger a PV wrapping
CLASSES ${velodyneplugin_classes} # Those will be PV ClientServer wrapped #shorcut for sources x.cxx x.h
HEADERS ${velodyneplugin_headers} # Those will be PV ClientServer wrapped
)
paraview_add_server_manager_xmls(
MODULE VelodyneLidar
XMLS ${velodyneplugin_xml}
)
# WIP Following line could be removed if explicit path are used in every header file, paraview style
target_include_directories(VelodyneLidar PUBLIC ${plugin_include_dirs} ) #Relax include path expliciteness, does not help wrapping
#-----------------------------------------------------------------------------
# The Python Bindings are kept for LEGACY REASON and is pending for removal
# Simply use "import VelodynePlugin.VelodyneLidar" and you have acces to the wrapped c++ code
# DO NOT FOR ANY REASON USE the method GetClientSideObject() to have acces to the vtkObject directly.
#-----------------------------------------------------------------------------
# Python Wrapping
if(NOT LV_INSTALL_PYTHON_MODULES_DIR)
message(FATAL_ERROR "LV_INSTALL_PYTHON_MODULES_DIR not set")
endif()
# Use import ${LV_LIDARPLUGIN_PYTHON_PKG}.VelodyneLidar
set(LV_VELODYNEPLUGIN_PYTHON_PKG "VelodynePlugin")
vtk_module_wrap_python(
MODULES VelodyneLidar # Target will be VelodyneLidarPython
BUILD_STATIC OFF
INSTALL_HEADERS OFF
PYTHON_PACKAGE "${LV_VELODYNEPLUGIN_PYTHON_PKG}" # This is the name of the python module to import
MODULE_DESTINATION "${LV_INSTALL_PYTHON_MODULES_DIR}" #"." #does not really like #without CMAKE_INSTALL_PREFIX
LIBRARY_DESTINATION "${LV_INSTALL_LIBRARY_DIR}"
DEPENDS VTK::vtkpythonmodules
)
#[[
# Install Python Module wrapped manually #Could be used to alleviate too long of a path?
add_custom_command(
TARGET VelodyneLidarPython POST_BUILD #could take them from ${CMAKE_PREFIX_PATH}, goes here for some reason
COMMAND ${CMAKE_COMMAND} -E copy_directory "${CMAKE_BINARY_DIR}/${LV_VELODYNEPLUGIN_PYTHON_PKG}" "${CMAKE_PREFIX_PATH}/${LV_INSTALL_PYTHON_MODULES_DIR}"
COMMENT "Install VelodyneLidarPython"
USES_TERMINAL
)
]]
# Install data files
set (calib_files
VLP-16.xml
HDL-32.xml
VLP-32c.xml
"Puck Hi-Res.xml"
"Puck LITE.xml"
"Alpha Prime.xml")
# Copy the calibration to the build folder
foreach(file ${calib_files})
configure_file("CalibrationsFiles/${file}" "${PROJECT_BINARY_DIR}/share/${file}" COPYONLY)
endforeach()
# Install step
set(installfile_dest share)
if(APPLE)
set(installfile_dest "${LV_INSTALL_LIBRARY_DIR}/../Resources")
endif()
foreach(file ${calib_files})
install(FILES "${PROJECT_BINARY_DIR}/share/${file}" DESTINATION ${installfile_dest})
endforeach()
#-----------------------------------------------------------------------------
# Option to build some tests
#-----------------------------------------------------------------------------
option(BUILD_TESTING "Build some unitary test" OFF)
if(BUILD_TESTING)
add_subdirectory(Testing)
endif()
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2013 Velodyne LiDAR
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
<ServerManagerConfiguration>
<!-- Begin vtkPlaneFitter -->
<ProxyGroup name="filters">
<SourceProxy name="PlaneFitter" class="vtkPlaneFitter" label="Plane Fitter">
<Documentation
short_help="Fit a plane on selection."
long_help="Fit a plane on the selected data and compute statistical informations.">
</Documentation>
<InputProperty
name="Input"
port_index="0"
command="SetInputConnection">
<ProxyGroupDomain name="groups">
<Group name="sources"/>
<Group name="filters"/>
</ProxyGroupDomain>
<DataTypeDomain name="input_type">
<DataType value="vtkPolyData"/>
</DataTypeDomain>
<Documentation>
Set the input poly data
</Documentation>
</InputProperty>
<StringVectorProperty name="SelectLaserIDArrayName"
label="laserIDArray"
command="SetInputArrayToProcess"
number_of_elements="5"
element_types="0 0 0 0 2"
default_values_delimiter=";"
default_values="0;0;0;0;laser_id"
animateable="0">
<ArrayListDomain name="array_list"
attribute_type="Scalars">
<RequiredProperties>
<Property name="Input"
function="Input" />
</RequiredProperties>
</ArrayListDomain>
</StringVectorProperty>
<OutputPort name="Statistics" index="0" id="port0" />
<OutputPort name="Model" index="1" id="port1" />
</SourceProxy>
</ProxyGroup>
<!-- End vtkPlaneFitter -->
</ServerManagerConfiguration>
// Copyright 2013 Velodyne Acoustics, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "vtkPlaneFitter.h"
#include "vtkHelper.h"
#include <Eigen/Dense>
#include <vtkObjectFactory.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkVariantArray.h>
#include <vtkUnstructuredGrid.h>
#include <vtkPolyData.h>
#include <vtkStringArray.h>
#include <vtkMath.h>
#include <vtkTable.h>
#include <vtkThreshold.h>
#include <vtkInformation.h>
#include <vtkInformationVector.h>
#include <vtkPlaneSource.h>
namespace {
//-----------------------------------------------------------------------------
struct PlaneStat {
std::string channelId = "";
Eigen::Vector3d origin = Eigen::Vector3d::Zero();
Eigen::Vector3d normal = Eigen::Vector3d::Zero();
double semiDist = 0.;
double nPts = 0.;
double mean = 0.;
double stddev = 0.;
double rms = 0.;
};
// if updateNormal is true, all stats are computed from rawData
// else they are all calculated except semiDist, origin and normal
bool ComputeStat(vtkSmartPointer<vtkDoubleArray> rawData,
std::string const & channelId,
PlaneStat& stat,
bool const & updateNormal = true)
{
if (!rawData)
{
vtkGenericWarningMacro("rawData empty");
return false;
}
unsigned int const nTuples = rawData->GetNumberOfTuples();
Eigen::Map<Eigen::MatrixXd> matData(static_cast<double*>(rawData->GetVoidPointer(0)),
rawData->GetNumberOfComponents(), nTuples);
double semiDist = 0.;
Eigen::Vector3d origin = Eigen::Vector3d::Zero();
Eigen::Vector3d normal = Eigen::Vector3d::Zero();
Eigen::MatrixXd centeredData;
if (updateNormal)
{
if (nTuples <= 2)
{
vtkGenericWarningMacro("Not enough tuples to compute normal");
return false;
}
origin = matData.rowwise().mean();
centeredData = (matData.colwise() - origin).transpose();
Eigen::JacobiSVD<Eigen::MatrixXd> svd(centeredData, Eigen::ComputeThinU | Eigen::ComputeThinV);
Eigen::VectorXd D = svd.singularValues();
normal = svd.matrixV().col(2);
semiDist = std::sqrt(D(0));
// Update computed semiDist, origin and normal
stat.semiDist = semiDist;
stat.origin = origin;
stat.normal = normal;
}
else
{
// Get semiDist, origin and normal from stat
semiDist = stat.semiDist;
origin = stat.origin;
normal = stat.normal;
centeredData = (matData.colwise() - origin).transpose();
}
// check if normal is valid
if ( semiDist < std::numeric_limits<double>::min() || normal.isZero(0) || (std::fabs(normal.norm() - 1.0) > 1.0e-8) )
{
vtkGenericWarningMacro("Invalid plane parameters");
return false;
}
Eigen::VectorXd distanceData = centeredData * normal;
if (distanceData.size() != nTuples)
{
vtkGenericWarningMacro("Inconsistent number of points in plane distances");
return false;
}
// Update remaining stats
stat.channelId = channelId;
stat.nPts = nTuples;
stat.mean = distanceData.mean();
stat.stddev = std::sqrt((distanceData.array() - stat.mean).matrix().squaredNorm() / (stat.nPts-1));
stat.rms = std::sqrt(std::pow(stat.mean,2.) + std::pow(stat.stddev,2.));
return true;
}
// Convert plane stats to vtkTable
vtkSmartPointer<vtkTable> convertToTable(std::vector<PlaneStat>& vStats)
{
unsigned int size = vStats.size();
unsigned int index = 0;
// Init Arrays for Table output
auto channelCol = createArray<vtkStringArray>("channel", 1, size);
auto originXCol = createArray<vtkDoubleArray>("originx", 1, size);
auto originYCol = createArray<vtkDoubleArray>("originy", 1, size);
auto originZCol = createArray<vtkDoubleArray>("originz", 1, size);
auto normalXCol = createArray<vtkDoubleArray>("normalx", 1, size);
auto normalYCol = createArray<vtkDoubleArray>("normaly", 1, size);
auto normalZCol = createArray<vtkDoubleArray>("normalz", 1, size);
auto meanCol = createArray<vtkDoubleArray>("mean" , 1, size);
auto stdDevCol = createArray<vtkDoubleArray>("stddev" , 1, size);
auto rmsCol = createArray<vtkDoubleArray>("rms" , 1, size);
auto ptsNbCol = createArray<vtkDoubleArray>("npts" , 1, size);
// Add row informations
for(auto stats : vStats)
{
channelCol->SetValue(index, stats.channelId);
originXCol->SetValue(index, stats.origin[0]);
originYCol->SetValue(index, stats.origin[1]);
originZCol->SetValue(index, stats.origin[2]);
normalXCol->SetValue(index, stats.normal[0]);
normalYCol->SetValue(index, stats.normal[1]);
normalZCol->SetValue(index, stats.normal[2]);
ptsNbCol->SetValue(index, stats.nPts);
meanCol->SetValue(index, stats.mean);
stdDevCol->SetValue(index, stats.stddev);
rmsCol->SetValue(index, stats.rms);
index++;
}
// Add columns to vtkTable
vtkSmartPointer<vtkTable> table = vtkSmartPointer<vtkTable>::New();
table->AddColumn(channelCol);
table->AddColumn(originXCol);
table->AddColumn(originYCol);
table->AddColumn(originZCol);
table->AddColumn(normalXCol);
table->AddColumn(normalYCol);
table->AddColumn(normalZCol);
table->AddColumn(meanCol);
table->AddColumn(stdDevCol);
table->AddColumn(rmsCol);
table->AddColumn(ptsNbCol);
return table;
}
// Create a vtk plane source
vtkSmartPointer<vtkPolyData> CreatePlane(double semiDist, Eigen::Vector3d origin, Eigen::Vector3d normal)
{
vtkSmartPointer<vtkPlaneSource> plane = vtkSmartPointer<vtkPlaneSource>::New();
plane->SetOrigin(-semiDist, -semiDist, 0.0);
plane->SetPoint1(semiDist, -semiDist, 0.0);
plane->SetPoint2(-semiDist, semiDist, 0.0);
plane->SetResolution(semiDist*2, semiDist*2);
plane->SetCenter(origin[0], origin[1], origin[2]);
plane->SetNormal(normal[0], normal[1], normal[2]);
plane->Update();
return plane->GetOutput();
}
}
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkPlaneFitter)
//-----------------------------------------------------------------------------
vtkPlaneFitter::vtkPlaneFitter()
{
this->SetNumberOfInputPorts(1);
this->SetNumberOfOutputPorts(2);
}
//-----------------------------------------------------------------------------
vtkPlaneFitter::~vtkPlaneFitter()
{
}
//-----------------------------------------------------------------------------
void vtkPlaneFitter::PrintSelf(ostream& os, vtkIndent indent)
{
this->Superclass::PrintSelf(os, indent);
}
//----------------------------------------------------------------------------
int vtkPlaneFitter::FillInputPortInformation(int port, vtkInformation *info)
{
if (port == 0)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData");
return 1;
}
return 0;
}
//----------------------------------------------------------------------------
int vtkPlaneFitter::FillOutputPortInformation(int port, vtkInformation *info)
{
if (port == 0)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkTable");
return 1;
}
if (port == 1)
{
info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData");
return 1;
}
return 0;
}
//-----------------------------------------------------------------------------
int vtkPlaneFitter::RequestData(vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector, vtkInformationVector *outputVector)
{
// Get the input
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
vtkPolyData* input = vtkPolyData::SafeDownCast(inInfo->Get(vtkDataObject::DATA_OBJECT()));
if (!input)
{
vtkErrorMacro("Null pointer entry, can not launch the filter");
return VTK_ERROR;
}
vtkDataArray* laserIndexArray = this->GetInputArrayToProcess(0, inputVector);
if (!laserIndexArray)
{
vtkErrorMacro( "The array " << laserIndexArray->GetName() << " is not valid, please update laserIDArray.");
return VTK_ERROR;
}
if(!input->GetPointData() || input->GetNumberOfPoints() <= 2)
{
vtkErrorMacro("Not enough points selected");
return VTK_ERROR;
}
vtkSmartPointer<vtkDoubleArray> data = vtkSmartPointer<vtkDoubleArray>::New();
data->DeepCopy(input->GetPoints()->GetData());
unsigned int max_laser_id = laserIndexArray->GetRange()[1];
unsigned int channelNb = static_cast<unsigned int>(std::pow(2, vtkMath::CeilLog2(max_laser_id)));
if(data->GetNumberOfComponents() != 3)
{
vtkErrorMacro("Invalid number of components");
return VTK_ERROR;
}
if (data->GetNumberOfTuples() == 0)
{
vtkErrorMacro("Not enough tuples");
return VTK_ERROR;
}
// Compute overall stats
std::vector<PlaneStat> vStats;
PlaneStat overallStats, channelStats;
if(!ComputeStat(data, std::string("overall"), overallStats))
{
vtkErrorMacro("Failed to compute overall statistics");
return VTK_ERROR;
}
vStats.push_back(overallStats);
// Compute per channel stats
vtkSmartPointer<vtkThreshold> threshold = vtkSmartPointer<vtkThreshold>::New();
threshold->SetInputData(input);
threshold->SetInputArrayToProcess(0, 0, 0, vtkDataObject::FIELD_ASSOCIATION_POINTS, laserIndexArray->GetName());
threshold->SetOutputPointsPrecision(vtkAlgorithm::DEFAULT_PRECISION);
// Update stats for each channel with overall stats
channelStats.semiDist = overallStats.semiDist;
channelStats.origin = overallStats.origin;
channelStats.normal = overallStats.normal;
for (unsigned int i = 0; i < channelNb; ++i)
{
threshold->ThresholdBetween(i, i);
threshold->Update();
data->DeepCopy(threshold->GetOutput()->GetPoints()->GetData());
if (data->GetNumberOfTuples() == 0)
{
continue;
}
if(!ComputeStat(data, std::to_string(i), channelStats, false))
{
vtkErrorMacro("Failed to compute per channel statistics");
return VTK_ERROR;
}
vStats.push_back(channelStats);
}
if (vStats.size() > channelNb + 1)
{
vtkErrorMacro("Inconsistent channel number");
return VTK_ERROR;
}
// Update outputs
// Update vtkTable output with vStats
vtkTable* outputTable = vtkTable::GetData(outputVector->GetInformationObject(0));
outputTable->ShallowCopy(convertToTable(vStats));
// Set the Output plane source
vtkPolyData* outputPlane = vtkPolyData::GetData(outputVector->GetInformationObject(1));
outputPlane->ShallowCopy(CreatePlane(overallStats.semiDist, overallStats.origin, overallStats.normal));
return VTK_OK;
}