Subject: CGAL users discussion list
List archive
- From: Yaoyu Hu <>
- To:
- Subject: Re: [cgal-discuss] How to read a PLY with properties as Point_set_3
- Date: Thu, 21 Oct 2021 03:38:09 -0400
- Authentication-results: mail3-smtp-sop.national.inria.fr; spf=None ; spf=Pass ; spf=None
- Ironport-hdrordr: A9a23:plxpd6oO67Pexi9XKzvmY3MaV5oFeYIsimQD101hICG9E/bo7vxH/pwguSMc7Qx/ZJhOo6HiBEDtewK/yXdV2/hrAV7AZniBhILLFvAH0WKK+VSJcEeSl45gPMxbAs9D4ajLfCRHZLHBkXaF+rgbsby6GdiT9JrjJiBWPHtXgtpbnn9E49mgfHFLeA==
- Ironport-phdr: A9a23:vqi4ehS67Yp0VuEqJCfCo3+95tpsop6YAWYlg6HPa5pwe6iut67vIFbYra00ygOTBcOKsrkZ1KL/iOPJYSQ4+5GPsXQPItRndiQuroEopTEmG9OPEkbhLfTnPGQQFcVGU0J5rTngaRAGUMnxaEfPrXKs8DUcBgvwNRZvJuTyB4Xek9m72/q99pHNfwlEnj6wba59IBi2rwjaq9Ubj5ZlJqst0BXCv2FGe/5RxWNmJFKTmwjz68Kt95N98Cpepuws+ddYXar1Y6o3Q7pYDC87M28u/83kqQPDTQqU6XQCVGgdjwdFDBLE7BH+WZfxrzf6u+9g0ySUIcH6UbY5Uimk4qx2ShHnlT0HOiY2/2HZiMN+jKxVrhG8qRJh34HZe5uaOOZkc67HYd8WWWhMU8BMXCJBGIO8aI4PAvIDMulCqIn8p0YOpga8CwmxGejizT9IhmL23KIg1OQgERzG0BEkEt8NsXnZt9r1NKIIXuC0yKnE1ynMb/RT2Trk7oXDbx8ur+2WU71qbcrR1VcgFxnDjliItIHoMTOY2OQPvmaU7OdtW+2ihmw5pwxxozWixccih43Xio8Xzl3J9jh0zYc6KNCkVkN2fdCqHYVMuiyZKYd7Q8UvSHxmtiY9z70Jo5+7fC4SxZs5wx7QdfmHfJaO4hL/TuqRJy13hHd7d76nhhay91KgyuzmWcWu3lZKtCxImcTPuHAVzxHf9NSLR/9n8kqi2TuDzR7f5v1HLEwumqfWKJgsyaMqmJUJq0TMBCr2lV32jKCIckUk/fCl6+H9bbXnop+QLpF7hRzjPqg3lMyyDuc1PhIBX2ic/uS827nj8lPjTLpWif02l7HVsJHcJcsFuq60GxFZ3pon5hqlDDqr0M4UkWcbIF9GYh6KgIvkN0nLIP/iDPe/h1qskC1sx/DDJrDhAojNL3jZn7fmfbd99lNQxQ4wwN1e/J9UBbQBL+jyWk/1rtDXEhg5Mwmsz+b9FNp9zp8eWX6IAqKBLKzSvkWH5uY2L+aRZY8VoyryK+U+5/71lnI5gl8cfayx3ZQNcny4H/JmI1+YYXX2mNsBH30K7UIDSvf3ggiCTSJLfCT1GLkt4ykyToOgF4bKAI63x6eQ2T+yWZxQaGcBAV+FFTLkdp6PRuwXOx+UOdJrsiABUe2hV5M5zkPp8xTrzqJuaOvS4CwR85z5k8Nk4vXa0hA0+zszBMuU1ySBTnp/g3gTFAIwx711nUFt1gKDzbRgmK4fUsdC4utAFAY8L5/VieJgTMvjXxrIOdaPRlHhSdqvBXQ9T8k63sQVMHp6Tt6thxSG0yuxCKIOjJSKAoY1++TSxSvfPcF4nkfP07g8x3k7Cp9PKHyvgb9irlmDWabGlkyYk+ChcqFKj32Fz3uK0Wfb5BIQawV3S6iQBRj3h2PTpNX9o07OFvqgVeRhPQxGxsqPbKBNb4+x5b2jbPjmMdXaJWm2njXobf5n7ryJZYvuPW4a2XeEYHU=
Thank you Andreas for the suggestion. The problem persists after adding the std::ios::binary argument.
#11 /home/yaoyu/Libraries/CGAL/cgal/Point_set_processing_3/include/CGAL/IO/read_ply_points.h:177
#12 /home/yaoyu/Libraries/CGAL/cgal/Point_set_processing_3/include/CGAL/IO/read_ply_points.h:196
Oh, I forgot to mention that I am on Ubuntu 20.04.
I still have the impression that I might have messed up in using the property maps.
I tried to debug what is wrong with gdb and I got the following error and a backtrace. I simplify it such that only the filename and line number are preserved. And also, I tried to list the relevant lines at some backtrace points.
=== Debug info. ===
terminate called after throwing an instance of 'CGAL::Assertion_exception'
what(): CGAL ERROR: assertion violation!
Expr: _idx < data_.size()
File: /home/yaoyu/Libraries/CGAL/cgal/Surface_mesh/include/CGAL/Surface_mesh/Properties.h
Line: 193
what(): CGAL ERROR: assertion violation!
Expr: _idx < data_.size()
File: /home/yaoyu/Libraries/CGAL/cgal/Surface_mesh/include/CGAL/Surface_mesh/Properties.h
Line: 193
#0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007ffff7642859 in __GI_abort () at abort.c:79
#2 0x00007ffff7a17911 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff7a2338c in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff7a233f7 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff7a236a9 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6 /home/yaoyu/Libraries/CGAL/cgal/STL_Extension/include/CGAL/assertions_impl.h:170
#7 /home/yaoyu/Libraries/CGAL/cgal/Surface_mesh/include/CGAL/Surface_mesh/Properties.h:193
#1 0x00007ffff7642859 in __GI_abort () at abort.c:79
#2 0x00007ffff7a17911 in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#3 0x00007ffff7a2338c in ?? () from /lib/x86_64-linux-gnu/libstdc++.so.6
#4 0x00007ffff7a233f7 in std::terminate() () from /lib/x86_64-linux-gnu/libstdc++.so.6
#5 0x00007ffff7a236a9 in __cxa_throw () from /lib/x86_64-linux-gnu/libstdc++.so.6
#6 /home/yaoyu/Libraries/CGAL/cgal/STL_Extension/include/CGAL/assertions_impl.h:170
#7 /home/yaoyu/Libraries/CGAL/cgal/Surface_mesh/include/CGAL/Surface_mesh/Properties.h:193
190 /// Access the i'th element. No range check is performed!
191 reference operator[](std::size_t _idx)
192 {
193 CGAL_assertion( _idx < data_.size() );
194 return data_[_idx];
195 }
191 reference operator[](std::size_t _idx)
192 {
193 CGAL_assertion( _idx < data_.size() );
194 return data_[_idx];
195 }
#8 /home/yaoyu/Libraries/CGAL/cgal/Surface_mesh/include/CGAL/Surface_mesh/Properties.h:587
583 /// Access the property associated with the key \c i.
584 reference operator[](const I& i) const
585 {
586 CGAL_assertion(parray_ != nullptr);
587 return (*parray_)[i];
588 }
589
590 iterator begin() { return parray_->begin(); }
591 iterator end() { return parray_->end(); }
584 reference operator[](const I& i) const
585 {
586 CGAL_assertion(parray_ != nullptr);
587 return (*parray_)[i];
588 }
589
590 iterator begin() { return parray_->begin(); }
591 iterator end() { return parray_->end(); }
#9 /usr/include/boost/property_map/property_map.hpp:311
307 template <class PropertyMap, class Reference, class K, class V>
308 inline void
309 put(const put_get_helper<Reference, PropertyMap>& pa, K k, const V& v)
310 {
311 static_cast<const PropertyMap&>(pa)[k] = v;
312 }
313
314 //=========================================================================
315 // Adapter to turn a RandomAccessIterator into a property map
308 inline void
309 put(const put_get_helper<Reference, PropertyMap>& pa, K k, const V& v)
310 {
311 static_cast<const PropertyMap&>(pa)[k] = v;
312 }
313
314 //=========================================================================
315 // Adapter to turn a RandomAccessIterator into a property map
#10 /home/yaoyu/Libraries/CGAL/cgal/Stream_support/include/CGAL/IO/PLY/PLY_reader.h:670
665 typedef typename boost::property_traits<PropertyMap>::value_type PmapValueType;
666
667 std::tuple<T...> values;
668 Filler<sizeof...(T)-1>::fill(element, values, current);
669 PmapValueType new_value = call_functor<PmapValueType>(std::get<1>(current), values);
670 put(std::get<0>(current), new_element, new_value);
671
672 process_properties(element, new_element, std::forward<NextPropertyBinder>(next),
673 std::forward<PropertyMapBinders>(properties)...);
666
667 std::tuple<T...> values;
668 Filler<sizeof...(T)-1>::fill(element, values, current);
669 PmapValueType new_value = call_functor<PmapValueType>(std::get<1>(current), values);
670 put(std::get<0>(current), new_element, new_value);
671
672 process_properties(element, new_element, std::forward<NextPropertyBinder>(next),
673 std::forward<PropertyMapBinders>(properties)...);
#11 /home/yaoyu/Libraries/CGAL/cgal/Point_set_processing_3/include/CGAL/IO/read_ply_points.h:177
172 }
173
174 if(element.name() == "vertex" || element.name() == "vertices")
175 {
176 OutputValueType new_element;
177 IO::internal::process_properties(element, new_element, std::forward<PropertyHandler>(properties)...);
178 *(output ++) = new_element;
179 }
180 }
181 }
173
174 if(element.name() == "vertex" || element.name() == "vertices")
175 {
176 OutputValueType new_element;
177 IO::internal::process_properties(element, new_element, std::forward<PropertyHandler>(properties)...);
178 *(output ++) = new_element;
179 }
180 }
181 }
#12 /home/yaoyu/Libraries/CGAL/cgal/Point_set_processing_3/include/CGAL/IO/read_ply_points.h:196
191 OutputIterator output,
192 PropertyHandler&& ... properties)
193 {
194 typedef typename value_type_traits<OutputIterator>::type OutputValueType;
195
196 return read_PLY_with_properties<OutputValueType>(is, output, std::forward<PropertyHandler>(properties)...);
197 }
198
199 /// \endcond
192 PropertyHandler&& ... properties)
193 {
194 typedef typename value_type_traits<OutputIterator>::type OutputValueType;
195
196 return read_PLY_with_properties<OutputValueType>(is, output, std::forward<PropertyHandler>(properties)...);
197 }
198
199 /// \endcond
=== End of debug info. ===
Thank you!
On Thu, Oct 21, 2021 at 2:10 AM Andreas Fabri <> wrote:
Hello,
At least on Windows if you read a binary ply file you must open the stream in binary mode.
Can you try std::ifstream ifs(fn, std::ios::binary);
Best,
Andreas
On 10/21/2021 1:20 AM, Yaoyu Hu ( via cgal-discuss Mailing List) wrote:
Hi,
I am trying to read a binary PLY file as CGAL::Point_set_3 but I can't get it right.
I am using CGAL 5.3.
I suppose there is not a dedicated example showing how to read a PLY file as Point_set_3 that has properties. For my PLY file, there are point normal and color stored. The code I tried to read it as CGAL::Point_set_3 is as follows:
=== Code begins. ===
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel_t;
typedef Kernel_t::Point_3 Point_t;
typedef Kernel_t::Vector_3 Vector_t;
typedef std::array< unsigned char, 3 > Color_t;
typedef CGAL::Point_set_3<Point_t> PointSet_t;typedef PointSet_t::Point_map PS_PointMap_t;
typedef PointSet_t::Vector_map PS_NormalMap_t;
typedef PointSet_t::Property_map<Color_t> PS_ColorMap_t;
PointSet_t sr::read_ply_as_point_set( const std::string& fn ) {
std::ifstream ifs(fn);
PointSet_t point_set;
// Default color.
const Color_t color_black { { 0, 0, 0 } };
// The color map.
PS_ColorMap_t color;
bool success = false;
boost::tie( color, success ) =
point_set.add_property_map<Color_t>("color", color_black);
assert (success);
// Read PLY.
CGAL::read_PLY_with_properties(
ifs,
point_set.index_back_inserter(),
CGAL::make_ply_point_reader( PS_PointMap_t() ),
CGAL::make_ply_normal_reader( PS_NormalMap_t() ),
std::make_tuple( PS_ColorMap_t(), CGAL::Construct_array(),
CGAL::PLY_property<unsigned char>("red"),
CGAL::PLY_property<unsigned char>("green"),
CGAL::PLY_property<unsigned char>("blue") ) ) )
return point_set;
}
=== Code ends. ===
The codes that I am not sure about are the lines of CGAL::make_ply_point_reader() and CGAL::make_ply_normal_reader(), they are probably wrong but I don't know how to get it right.
Thanks!
Yaoyu
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss
-- Andreas Fabri, PhD Chief Officer, GeometryFactory Editor, The CGAL Project
--
You are currently subscribed to cgal-discuss.
To unsubscribe or access the archives, go to
https://sympa.inria.fr/sympa/info/cgal-discuss
- [cgal-discuss] How to read a PLY with properties as Point_set_3, Yaoyu Hu, 10/21/2021
- Re: [cgal-discuss] How to read a PLY with properties as Point_set_3, Andreas Fabri, 10/21/2021
- Re: [cgal-discuss] How to read a PLY with properties as Point_set_3, Yaoyu Hu, 10/21/2021
- Re: [cgal-discuss] How to read a PLY with properties as Point_set_3, Yaoyu Hu, 10/23/2021
- Re: [cgal-discuss] How to read a PLY with properties as Point_set_3, Yaoyu Hu, 10/21/2021
- Re: [cgal-discuss] How to read a PLY with properties as Point_set_3, Andreas Fabri, 10/21/2021
Archive powered by MHonArc 2.6.19+.