From f8f30d132862a9094d3be9b04c517b93c74ec361 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Couble?= Date: Tue, 25 Feb 2025 10:00:38 +0100 Subject: [PATCH 1/3] [refact] Clang-format & update license header --- .../Temporal/vtkTemporalTransformsApplier.cxx | 68 +++++++-------- .../Temporal/vtkTemporalTransformsApplier.h | 84 +++++++++---------- 2 files changed, 76 insertions(+), 76 deletions(-) diff --git a/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx b/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx index 2b548ebb6..612db6dcc 100644 --- a/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx +++ b/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx @@ -1,16 +1,17 @@ -// Copyright 2019 Kitware SAS. -// -// 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. +/*========================================================================= + + Program: LidarView + Module: vtkTemporalTransformApplier.cxx + + Copyright (c) Kitware Inc. + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ #include "vtkTemporalTransformsApplier.h" @@ -47,8 +48,8 @@ vtkMTimeType vtkTemporalTransformsApplier::GetMTime() //----------------------------------------------------------------------------- int vtkTemporalTransformsApplier::RequestData(vtkInformation* vtkNotUsed(request), - vtkInformationVector** inputVector, - vtkInformationVector* outputVector) + vtkInformationVector** inputVector, + vtkInformationVector* outputVector) { // Get the input vtkPolyData* pointcloud = vtkPolyData::GetData(inputVector[1]->GetInformationObject(0)); @@ -59,12 +60,11 @@ int vtkTemporalTransformsApplier::RequestData(vtkInformation* vtkNotUsed(request // Fill the interpolator if (this->Interpolator->GetNumberOfTransforms() == 0) { - auto type = this->Interpolator->GetInterpolationType(); + auto type = this->Interpolator->GetInterpolationType(); this->Interpolator = trajectory->CreateInterpolator(); this->Interpolator->SetInterpolationType(type); } - // Copy the input and create some new points vtkPolyData* output = vtkPolyData::GetData(outputVector); output->ShallowCopy(pointcloud); @@ -77,21 +77,21 @@ int vtkTemporalTransformsApplier::RequestData(vtkInformation* vtkNotUsed(request if (!this->InterpolateEachPoint) { // get timestamp - vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); + vtkInformation* inInfo = inputVector[0]->GetInformationObject(0); double currentTimestamp = inInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_TIME_STEP()); // get the right transform auto transform = vtkSmartPointer::New(); - this->Interpolator->InterpolateTransform(currentTimestamp,transform); + this->Interpolator->InterpolateTransform(currentTimestamp, transform); transform->Update(); // apply the transform for (vtkIdType i = 0; i < pointcloud->GetNumberOfPoints(); i++) { - float* inputPoint = reinterpret_cast - (pointcloud->GetPoints()->GetData()->WriteVoidPointer(3*i,1)); - float* outputPoint = reinterpret_cast - (output->GetPoints()->GetData()->WriteVoidPointer(3*i,1)); + float* inputPoint = + reinterpret_cast(pointcloud->GetPoints()->GetData()->WriteVoidPointer(3 * i, 1)); + float* outputPoint = + reinterpret_cast(output->GetPoints()->GetData()->WriteVoidPointer(3 * i, 1)); transform->InternalTransformPoint(inputPoint, outputPoint); } } @@ -102,7 +102,7 @@ int vtkTemporalTransformsApplier::RequestData(vtkInformation* vtkNotUsed(request auto timestamp = this->GetInputArrayToProcess(0, inputVector); if (!timestamp) { - vtkErrorMacro(<<"No TimeStamp array selected."); + vtkErrorMacro(<< "No TimeStamp array selected."); return 1; } for (vtkIdType i = 0; i < pointcloud->GetNumberOfPoints(); i++) @@ -112,29 +112,28 @@ int vtkTemporalTransformsApplier::RequestData(vtkInformation* vtkNotUsed(request // get the right transform auto transform = vtkSmartPointer::New(); - this->Interpolator->InterpolateTransform(currentTimestamp,transform); + this->Interpolator->InterpolateTransform(currentTimestamp, transform); transform->Update(); // apply the transform - float* inputPoint = reinterpret_cast - (pointcloud->GetPoints()->GetData()->WriteVoidPointer(3*i,1)); - float* outputPoint = reinterpret_cast - (output->GetPoints()->GetData()->WriteVoidPointer(3*i,1)); + float* inputPoint = + reinterpret_cast(pointcloud->GetPoints()->GetData()->WriteVoidPointer(3 * i, 1)); + float* outputPoint = + reinterpret_cast(output->GetPoints()->GetData()->WriteVoidPointer(3 * i, 1)); transform->InternalTransformPoint(inputPoint, outputPoint); } } - return 1; } //----------------------------------------------------------------------------- int vtkTemporalTransformsApplier::RequestInformation(vtkInformation* vtkNotUsed(request), - vtkInformationVector** inputVector, - vtkInformationVector* outputVector) + vtkInformationVector** inputVector, + vtkInformationVector* outputVector) { // indicate that this filter produce continuous timstep in the interpolator range vtkInformation* outInfo = outputVector->GetInformationObject(0); - double timeRange[2] = {this->Interpolator->GetMinimumT(), this->Interpolator->GetMaximumT()}; + double timeRange[2] = { this->Interpolator->GetMinimumT(), this->Interpolator->GetMaximumT() }; outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_RANGE(), timeRange, 2); // Propagate the information that steps are available: @@ -147,6 +146,7 @@ int vtkTemporalTransformsApplier::RequestInformation(vtkInformation* vtkNotUsed( { timesteps.push_back(inInfo->Get(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), i)); } - outInfo->Set(vtkStreamingDemandDrivenPipeline::TIME_STEPS(), ×teps.front(), timesteps.size()); + outInfo->Set( + vtkStreamingDemandDrivenPipeline::TIME_STEPS(), ×teps.front(), timesteps.size()); return 1; } diff --git a/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.h b/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.h index 090247c6f..39453598d 100644 --- a/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.h +++ b/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.h @@ -1,19 +1,20 @@ -// Copyright 2019 Kitware SAS. -// -// 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. - -#ifndef TemporalTransformsAPPLIER_H -#define TemporalTransformsAPPLIER_H +/*========================================================================= + + Program: LidarView + Module: vtkTemporalTransformApplier.h + + Copyright (c) Kitware Inc. + All rights reserved. + See Copyright.txt or http://www.kitware.com/Copyright.htm for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notice for more information. + +=========================================================================*/ + +#ifndef vtkTemporalTransformApplier_h +#define vtkTemporalTransformApplier_h #include #include @@ -32,11 +33,17 @@ class LVFILTERSTEMPORAL_EXPORT vtkTemporalTransformsApplier : public vtkPolyData { public: static vtkTemporalTransformsApplier* New(); - vtkTypeMacro(vtkTemporalTransformsApplier,vtkPolyDataAlgorithm) + vtkTypeMacro(vtkTemporalTransformsApplier, vtkPolyDataAlgorithm); + + /** + * Override GetMTime() because we depend on the TransformInterpolator + * which may be modified outside of this class. + */ + vtkMTimeType GetMTime() override; //@{ /** - * @copydoc vtkTemporalTransformsApplier::InterpolationType + * Interpolator used to get the right transform */ int GetInterpolationType() { return this->Interpolator->GetInterpolationType(); } void SetInterpolationType(int value) { this->Interpolator->SetInterpolationType(value); }; @@ -44,48 +51,41 @@ public: //@{ /** - * @copydoc vtkTemporalTransformsApplier::InterpolateEachPoint + * Indicate if a different transform should be apply to each point, + * or if the same transform should be apply to the whole point cloud. + * In the first case you must specify the array from the pointcloud containing the + * timestamp with 'SetInputArrayToProcess' */ - vtkGetMacro(InterpolateEachPoint, bool) - vtkSetMacro(InterpolateEachPoint, bool) + vtkGetMacro(InterpolateEachPoint, bool); + vtkSetMacro(InterpolateEachPoint, bool); //@} + //@{ /** - * @brief Override GetMTime() because we depend on the TransformInterpolator - * which may be modified outside of this class. + * Convert time in second default is for data in microsecond */ - vtkMTimeType GetMTime() override; - - vtkGetMacro(ConversionFactorToSecond, double) - vtkSetMacro(ConversionFactorToSecond, double) + vtkGetMacro(ConversionFactorToSecond, double); + vtkSetMacro(ConversionFactorToSecond, double); + //@} protected: vtkTemporalTransformsApplier(); int RequestInformation(vtkInformation* request, - vtkInformationVector** inputVector, - vtkInformationVector* outputVector) override; + vtkInformationVector** inputVector, + vtkInformationVector* outputVector) override; int RequestData(vtkInformation* request, - vtkInformationVector** inputVector, - vtkInformationVector* outputVector) override; + vtkInformationVector** inputVector, + vtkInformationVector* outputVector) override; private: - //! Indicate if a different transform should be apply to each point, - //! or if the same transform should be apply to the whole point cloud. - //! In the first case you must specify the array from the pointcloud containing the - //! timestamp with 'SetInputArrayToProcess' bool InterpolateEachPoint; - - //! Interpolator used to get the right transform vtkSmartPointer Interpolator; - - //! double to convert time in second, - //! default is for data in microsecond double ConversionFactorToSecond = 1e-6; vtkTemporalTransformsApplier(const vtkTemporalTransformsApplier&) /*= delete*/; - void operator =(const vtkTemporalTransformsApplier&) /*= delete*/; + void operator=(const vtkTemporalTransformsApplier&) /*= delete*/; }; -#endif // TemporalTransformsAPPLIER_H +#endif // vtkTemporalTransformApplier_h -- GitLab From c15dd9faef61efbabf55896efc0d008f3e673f80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Couble?= Date: Tue, 25 Feb 2025 10:21:54 +0100 Subject: [PATCH 2/3] [fix] Improve error handling in temporal transform applier --- .../Filters/Temporal/vtkTemporalTransformsApplier.cxx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx b/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx index 612db6dcc..174b0f32a 100644 --- a/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx +++ b/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx @@ -56,6 +56,11 @@ int vtkTemporalTransformsApplier::RequestData(vtkInformation* vtkNotUsed(request vtkPolyData* input = vtkPolyData::GetData(inputVector[0]->GetInformationObject(0)); auto trajectory = vtkTemporalTransforms::CreateFromPolyData(input); + if (!trajectory) + { + vtkErrorMacro(<< "Invalid trajectory."); + return 0; + } // Fill the interpolator if (this->Interpolator->GetNumberOfTransforms() == 0) @@ -103,7 +108,7 @@ int vtkTemporalTransformsApplier::RequestData(vtkInformation* vtkNotUsed(request if (!timestamp) { vtkErrorMacro(<< "No TimeStamp array selected."); - return 1; + return 0; } for (vtkIdType i = 0; i < pointcloud->GetNumberOfPoints(); i++) { -- GitLab From 8df4e76a24f67fb5a4def2615231cb5eb1260778 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timoth=C3=A9e=20Couble?= Date: Tue, 25 Feb 2025 10:28:49 +0100 Subject: [PATCH 3/3] [refact] Improve temporal transform applier documentation xml --- .../Temporal/vtkTemporalTransformsApplier.cxx | 4 +- .../Filters/TemporalTransformsApplier.xml | 188 +++++++++--------- 2 files changed, 100 insertions(+), 92 deletions(-) diff --git a/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx b/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx index 174b0f32a..3b83f7fa3 100644 --- a/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx +++ b/LidarCore/Filters/Temporal/vtkTemporalTransformsApplier.cxx @@ -52,8 +52,8 @@ int vtkTemporalTransformsApplier::RequestData(vtkInformation* vtkNotUsed(request vtkInformationVector* outputVector) { // Get the input - vtkPolyData* pointcloud = vtkPolyData::GetData(inputVector[1]->GetInformationObject(0)); - vtkPolyData* input = vtkPolyData::GetData(inputVector[0]->GetInformationObject(0)); + vtkPolyData* pointcloud = vtkPolyData::GetData(inputVector[0]->GetInformationObject(0)); + vtkPolyData* input = vtkPolyData::GetData(inputVector[1]->GetInformationObject(0)); auto trajectory = vtkTemporalTransforms::CreateFromPolyData(input); if (!trajectory) diff --git a/Plugins/LidarCorePlugin/Filters/TemporalTransformsApplier.xml b/Plugins/LidarCorePlugin/Filters/TemporalTransformsApplier.xml index c467170ae..5663edaae 100644 --- a/Plugins/LidarCorePlugin/Filters/TemporalTransformsApplier.xml +++ b/Plugins/LidarCorePlugin/Filters/TemporalTransformsApplier.xml @@ -1,102 +1,110 @@ - - + + + Using LiDAR frames and a SLAM trajectory, this filter applies the current transform corresponding to either the pipeline time or the current points time. - - - - - - - - - - Set the input trajectory - - + + + + + + + + + + Set the input point cloud + + - - - - - - - - - - Set the input point cloud - - + + + + + + + + + + Set the input trajectory + + - - - - - - - - - - This property indicates which type of interpolation will be used. - - + + + + + + + + + + The type of interpolation to use. + + - - - - This property indicates if each point will be interpolate independanly according to its timestamp - - + + + + Indicates if each point should be interpolated independently according to its timestamp or + if the same transform should be applied to the whole point cloud. + + - - - - - - - - - - + + + + + + + + Select the corresponding time array name. + + + + + - - - Double to convert Time unit in second, default is microsecond - - + + + Factor to convert Time unit in second, default is microsecond. + + + + + - + -- GitLab