@@ -74,7 +74,12 @@ class ColoredTSDFVolumeCPU : public ColoredTSDFVolume
7474 { CV_Error (Error::StsNotImplemented, " Not implemented" ); };
7575
7676 virtual void fetchNormals (InputArray points, OutputArray _normals) const override ;
77- virtual void fetchPointsNormals (OutputArray points, OutputArray normals) const override ;
77+ void fetchPointsNormalsColors (OutputArray points, OutputArray normals, OutputArray colors) const override ;
78+
79+ void fetchPointsNormals (OutputArray points, OutputArray normals) const override
80+ {
81+ fetchPointsNormalsColors (points, normals, noArray ());
82+ }
7883
7984 virtual void reset () override ;
8085 virtual RGBTsdfVoxel at (const Vec3i& volumeIdx) const ;
@@ -837,17 +842,20 @@ struct ColorFetchPointsNormalsInvoker : ParallelLoopBody
837842 ColorFetchPointsNormalsInvoker (const ColoredTSDFVolumeCPU& _volume,
838843 std::vector<std::vector<ptype>>& _pVecs,
839844 std::vector<std::vector<ptype>>& _nVecs,
840- bool _needNormals) :
845+ std::vector<std::vector<ptype>>& _cVecs,
846+ bool _needNormals, bool _needColors) :
841847 ParallelLoopBody (),
842848 vol (_volume),
843849 pVecs (_pVecs),
844850 nVecs (_nVecs),
845- needNormals (_needNormals)
851+ cVecs (_cVecs),
852+ needNormals (_needNormals),
853+ needColors (_needColors)
846854 {
847855 volDataStart = vol.volume .ptr <RGBTsdfVoxel>();
848856 }
849857
850- inline void coord (std::vector<ptype>& points, std::vector<ptype>& normals,
858+ inline void coord (std::vector<ptype>& points, std::vector<ptype>& normals, std::vector<ptype>& colors,
851859 int x, int y, int z, Point3f V, float v0, int axis) const
852860 {
853861 // 0 for x, 1 for y, 2 for z
@@ -897,6 +905,8 @@ struct ColorFetchPointsNormalsInvoker : ParallelLoopBody
897905 if (needNormals)
898906 normals.push_back (toPtype (vol.pose .rotation () *
899907 vol.getNormalVoxel (p*vol.voxelSizeInv )));
908+ if (needColors)
909+ colors.push_back (toPtype (vol.getColorVoxel (p*vol.voxelSizeInv )));
900910 }
901911 }
902912 }
@@ -905,7 +915,7 @@ struct ColorFetchPointsNormalsInvoker : ParallelLoopBody
905915
906916 virtual void operator () (const Range& range) const override
907917 {
908- std::vector<ptype> points, normals;
918+ std::vector<ptype> points, normals, colors ;
909919 for (int x = range.start ; x < range.end ; x++)
910920 {
911921 const RGBTsdfVoxel* volDataX = volDataStart + x*vol.volDims [0 ];
@@ -920,9 +930,9 @@ struct ColorFetchPointsNormalsInvoker : ParallelLoopBody
920930 {
921931 Point3f V (Point3f ((float )x + 0 .5f , (float )y + 0 .5f , (float )z + 0 .5f )*vol.voxelSize );
922932
923- coord (points, normals, x, y, z, V, v0, 0 );
924- coord (points, normals, x, y, z, V, v0, 1 );
925- coord (points, normals, x, y, z, V, v0, 2 );
933+ coord (points, normals, colors, x, y, z, V, v0, 0 );
934+ coord (points, normals, colors, x, y, z, V, v0, 1 );
935+ coord (points, normals, colors, x, y, z, V, v0, 2 );
926936
927937 } // if voxel is not empty
928938 }
@@ -932,32 +942,36 @@ struct ColorFetchPointsNormalsInvoker : ParallelLoopBody
932942 AutoLock al (mutex);
933943 pVecs.push_back (points);
934944 nVecs.push_back (normals);
945+ cVecs.push_back (colors);
935946 }
936947
937948 const ColoredTSDFVolumeCPU& vol;
938949 std::vector<std::vector<ptype>>& pVecs;
939950 std::vector<std::vector<ptype>>& nVecs;
951+ std::vector<std::vector<ptype>>& cVecs;
940952 const RGBTsdfVoxel* volDataStart;
941953 bool needNormals;
954+ bool needColors;
942955 mutable Mutex mutex;
943956};
944957
945- void ColoredTSDFVolumeCPU::fetchPointsNormals (OutputArray _points, OutputArray _normals) const
958+ void ColoredTSDFVolumeCPU::fetchPointsNormalsColors (OutputArray _points, OutputArray _normals, OutputArray _colors ) const
946959{
947960 CV_TRACE_FUNCTION ();
948961
949962 if (_points.needed ())
950963 {
951- std::vector<std::vector<ptype>> pVecs, nVecs;
952- ColorFetchPointsNormalsInvoker fi (*this , pVecs, nVecs, _normals.needed ());
964+ std::vector<std::vector<ptype>> pVecs, nVecs, cVecs ;
965+ ColorFetchPointsNormalsInvoker fi (*this , pVecs, nVecs, cVecs, _normals. needed (), _colors .needed ());
953966 Range range (0 , volResolution.x );
954967 const int nstripes = -1 ;
955968 parallel_for_ (range, fi, nstripes);
956- std::vector<ptype> points, normals;
969+ std::vector<ptype> points, normals, colors ;
957970 for (size_t i = 0 ; i < pVecs.size (); i++)
958971 {
959972 points.insert (points.end (), pVecs[i].begin (), pVecs[i].end ());
960973 normals.insert (normals.end (), nVecs[i].begin (), nVecs[i].end ());
974+ colors.insert (colors.end (), cVecs[i].begin (), cVecs[i].end ());
961975 }
962976
963977 _points.create ((int )points.size (), 1 , POINT_TYPE);
@@ -970,6 +984,13 @@ void ColoredTSDFVolumeCPU::fetchPointsNormals(OutputArray _points, OutputArray _
970984 if (!normals.empty ())
971985 Mat ((int )normals.size (), 1 , POINT_TYPE, &normals[0 ]).copyTo (_normals.getMat ());
972986 }
987+
988+ if (_colors.needed ())
989+ {
990+ _colors.create ((int )colors.size (), 1 , COLOR_TYPE);
991+ if (!colors.empty ())
992+ Mat ((int )colors.size (), 1 , COLOR_TYPE, &colors[0 ]).copyTo (_colors.getMat ());
993+ }
973994 }
974995}
975996
0 commit comments