2 * This program is free software: you can redistribute it and/or modify
3 * it under the terms of the GNU Lesser General Public License as
4 * published by the Free Software Foundation, either version 3 of the
5 * License, or (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 * @file LambdaMST3DBy2D.ih
19 * @author Kacper Pluta (\c kacper.pluta@esiee.fr )
20 * Laboratoire d'Informatique Gaspard-Monge - LIGM, France
24 * This file is part of the DGtal library.
32 TangentFromDSS3DBy2DFunctor::Vector3D
33 TangentFromDSS3DBy2DFunctor::operator() ( MAIN_AXIS mainAxis, const Vector2D & v0, const Vector2D & v1 ) const
38 if ( v1[1] == 0 || ( v0[0] == 0 && v1[0] == 0 ) )
54 tangent[0] = v1[0] * v0[0];
55 tangent[1] = v1[0] * v0[1];
56 tangent[2] = v0[0] * v1[1];
60 else if ( mainAxis == Y )
62 if ( v0[0] == 0 || ( v1[0] == 0 && v0[1] == 0 ) )
78 tangent[0] = v1[0] * v0[0];
79 tangent[1] = v1[0] * v0[1];
80 tangent[2] = v0[1] * v1[1];
86 if ( v0[0] == 0 || ( v0[1] == 0 && v1[1] == 0 ) )
102 tangent[0] = v0[0] * v1[1];
103 tangent[1] = v1[0] * v0[1];
104 tangent[2] = v0[1] * v1[1];
112 template < typename Iterator3D, typename Functor, typename LambdaFunctor, int CONNECTIVITY >
114 LambdaMST3DBy2DEstimator< Iterator3D, Functor, LambdaFunctor, CONNECTIVITY >::LambdaMST3DBy2DEstimator() : myBegin(), myEnd()
117 std::vector < Dimension > v1, v2, v3;
124 myProjXY.init ( v1.begin ( ), v1.end ( ) );
125 myProjXZ.init ( v2.begin ( ), v2.end ( ) );
126 myProjYZ.init ( v3.begin ( ), v3.end ( ) );
129 template < typename Iterator3D, typename Functor, typename LambdaFunctor, int CONNECTIVITY >
132 LambdaMST3DBy2DEstimator< Iterator3D, Functor, LambdaFunctor, CONNECTIVITY >::init ( Iterator3D itB, Iterator3D itE,
138 tXY.clear ( ); tYZ.clear ( ); tXZ.clear ( );
139 for ( auto it = myBegin; it != myEnd; ++it )
141 if ( axis == MAIN_AXIS::X )
143 tXY.push_back ( myProjXY ( *it ) );
144 tXZ.push_back ( myProjXZ ( *it ) );
146 else if ( axis == MAIN_AXIS::Y )
148 tXY.push_back ( myProjXY ( *it ) );
149 tYZ.push_back ( myProjYZ ( *it ) );
153 tXZ.push_back ( myProjXZ ( *it ) );
154 tYZ.push_back ( myProjYZ ( *it ) );
159 template < typename Iterator3D, typename Functor, typename LambdaFunctor, int CONNECTIVITY >
162 LambdaMST3DBy2DEstimator< Iterator3D, Functor, LambdaFunctor, CONNECTIVITY >::isValid ( ) const
164 return ( myBegin != myEnd );
167 template < typename Iterator3D, typename Functor, typename LambdaFunctor, int CONNECTIVITY >
169 typename LambdaMST3DBy2DEstimator< Iterator3D, Functor, LambdaFunctor, CONNECTIVITY >::RealVector3D
170 LambdaMST3DBy2DEstimator< Iterator3D, Functor, LambdaFunctor, CONNECTIVITY >::eval ( const Point3D & point )
172 assert ( isValid ( ) );
173 Iterator3D it = std::find ( myBegin, myEnd, point );
175 throw std::runtime_error ( "L-MST3Dby2D::eval: The point does not belong to the curve!" );
177 if ( myAxis == MAIN_AXIS::X )
178 return myFunctor ( MAIN_AXIS::X, Estimate2DTangent ( tXY.cbegin ( ), tXY.cend ( ), myProjXY ( *it ) ),
179 Estimate2DTangent ( tXZ.cbegin ( ), tXZ.cend ( ), myProjXZ ( *it ) ) );
180 else if ( myAxis == MAIN_AXIS::Y )
181 return myFunctor ( MAIN_AXIS::Y, Estimate2DTangent ( tXY.cbegin ( ), tXY.cend ( ), myProjXY ( *it ) ),
182 Estimate2DTangent ( tYZ.cbegin ( ), tYZ.cend ( ), myProjYZ ( *it ) ) );
184 return myFunctor ( MAIN_AXIS::Z, Estimate2DTangent ( tXZ.cbegin ( ), tXZ.cend ( ), myProjXZ ( *it ) ),
185 Estimate2DTangent ( tYZ.cbegin ( ), tYZ.cend ( ), myProjYZ ( *it ) ) );
188 template < typename Iterator3D, typename Functor, typename LambdaFunctor, int CONNECTIVITY >
189 template < typename OutputIterator >
192 LambdaMST3DBy2DEstimator< Iterator3D, Functor, LambdaFunctor, CONNECTIVITY >::eval ( Iterator3D itb, Iterator3D ite,
193 OutputIterator result )
195 assert ( myBegin != myEnd && isValid() && myBegin <= itb && ite <= myEnd && itb != ite );
196 std::vector < RealVector2D > tangent1;
197 std::vector < RealVector2D > tangent2;
199 auto offsetB = std::distance ( myBegin, itb );
200 auto offsetE = std::distance ( myEnd, ite );
202 if ( myAxis == MAIN_AXIS::X )
204 Estimate2DTangent ( tXY.cbegin ( ) + offsetB, tXY.cend ( ) + offsetE, back_inserter ( tangent1 ) );
205 Estimate2DTangent ( tXZ.cbegin ( ) + offsetB, tXZ.cend ( ) + offsetE, back_inserter ( tangent2 ) );
207 else if ( myAxis == MAIN_AXIS::Y )
209 Estimate2DTangent ( tXY.cbegin ( ) + offsetB, tXY.cend ( ) + offsetE, back_inserter ( tangent1 ) );
210 Estimate2DTangent ( tYZ.cbegin ( ) + offsetB, tYZ.cend ( ) + offsetE, back_inserter ( tangent2 ) );
214 Estimate2DTangent ( tXZ.cbegin ( ) + offsetB, tXZ.cend ( ) + offsetE, back_inserter ( tangent1 ) );
215 Estimate2DTangent ( tYZ.cbegin ( ) + offsetB, tYZ.cend ( ) + offsetE, back_inserter ( tangent2 ) );
218 for ( auto it = itb; it < ite; ++it )
219 result++ = myFunctor ( myAxis, tangent1[std::distance ( itb, it )], tangent2[std::distance ( itb, it )] );
225 template < typename Iterator3D, typename Functor, typename LambdaFunctor, int CONNECTIVITY >
227 typename LambdaMST3DBy2DEstimator< Iterator3D, Functor, LambdaFunctor, CONNECTIVITY >::RealVector2D
228 LambdaMST3DBy2DEstimator< Iterator3D, Functor, LambdaFunctor, CONNECTIVITY >::Estimate2DTangent
229 ( const TCurve2D::const_iterator itb, TCurve2D::const_iterator ite, const Point2D & point )
231 Segmentation2D segmenter ( itb, ite, SegmentComputer2D ( ) );
233 lmst.attach ( segmenter );
234 lmst.init ( itb, ite );
235 return lmst.eval ( point );
239 template < typename Iterator3D, typename Functor, typename LambdaFunctor, int CONNECTIVITY >
240 template < typename OutputIterator >
243 LambdaMST3DBy2DEstimator< Iterator3D, Functor, LambdaFunctor, CONNECTIVITY >::Estimate2DTangent
244 ( TCurve2D::const_iterator itb, TCurve2D::const_iterator ite, OutputIterator result )
246 Segmentation2D segmenter ( itb, ite, SegmentComputer2D ( ) );
248 lmst.attach ( segmenter );
249 lmst.init ( itb, ite );
250 return lmst.eval ( itb, ite, result );