Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r65936 - sandbox/geometry/libs/geometry/example
From: barend.gehrels_at_[hidden]
Date: 2010-10-13 07:33:29


Author: barendgehrels
Date: 2010-10-13 07:33:26 EDT (Wed, 13 Oct 2010)
New Revision: 65936
URL: http://svn.boost.org/trac/boost/changeset/65936

Log:
Added two samples related to boost mailing list
Added:
   sandbox/geometry/libs/geometry/example/c10_custom_cs_example.cpp (contents, props changed)
   sandbox/geometry/libs/geometry/example/c10_custom_cs_example.vcproj (contents, props changed)
   sandbox/geometry/libs/geometry/example/c11_custom_cs_transform_example.cpp (contents, props changed)
   sandbox/geometry/libs/geometry/example/c11_custom_cs_transform_example.vcproj (contents, props changed)
Text files modified:
   sandbox/geometry/libs/geometry/example/Jamfile.v2 | 5 +++++
   sandbox/geometry/libs/geometry/example/c09_custom_fusion_example.cpp | 3 ++-
   sandbox/geometry/libs/geometry/example/custom_examples.sln | 12 ++++++++++++
   3 files changed, 19 insertions(+), 1 deletions(-)

Modified: sandbox/geometry/libs/geometry/example/Jamfile.v2
==============================================================================
--- sandbox/geometry/libs/geometry/example/Jamfile.v2 (original)
+++ sandbox/geometry/libs/geometry/example/Jamfile.v2 2010-10-13 07:33:26 EDT (Wed, 13 Oct 2010)
@@ -28,4 +28,9 @@
 exe c04_b_custom_triangle_example : c04_b_custom_triangle_example.cpp ;
 exe c06_custom_polygon_example : c06_custom_polygon_example.cpp ;
 exe c07_custom_ring_pointer_example : c07_custom_ring_pointer_example.cpp ;
+
 # exe c08_custom_non_std_example : c08_custom_non_std_example.cpp ;
+# c09 is not yet finished
+
+exe c10_custom_cs_example : c10_custom_cs_example.cpp ;
+exe c11_custom_cs_transform_example : c11_custom_cs_transform_example.cpp ;

Modified: sandbox/geometry/libs/geometry/example/c09_custom_fusion_example.cpp
==============================================================================
--- sandbox/geometry/libs/geometry/example/c09_custom_fusion_example.cpp (original)
+++ sandbox/geometry/libs/geometry/example/c09_custom_fusion_example.cpp 2010-10-13 07:33:26 EDT (Wed, 13 Oct 2010)
@@ -6,6 +6,7 @@
 // http://www.boost.org/LICENSE_1_0.txt)
 //
 // Custom point / fusion Example
+// NOT FINISHED
 
 #include <iostream>
 
@@ -47,7 +48,7 @@
 
     std::cout << boost::fusion::at_c<1>(p1) << std::endl;
 
- std::cout << boost::geometry::get<1>(p1) << std::endl;
+ //std::cout << boost::geometry::get<1>(p1) << std::endl;
 
     return 0;
 }

Added: sandbox/geometry/libs/geometry/example/c10_custom_cs_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/example/c10_custom_cs_example.cpp 2010-10-13 07:33:26 EDT (Wed, 13 Oct 2010)
@@ -0,0 +1,103 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Copyright Barend Gehrels 2010, Geodan, Amsterdam, the Netherlands
+// Use, modification and distribution is subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// Example: Custom coordinate system example
+
+#include <iostream>
+
+#include <boost/geometry/geometry.hpp>
+
+#ifdef OPTIONALLY_ELLIPSOIDAL // see below
+#include <boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp>
+#endif
+
+// 1: declare a coordinate system. For example for Mars
+// Like for the Earth, we let the use choose between degrees or radians
+// (Unfortunately, in real life Mars has two coordinate systems:
+// http://planetarynames.wr.usgs.gov/Page/MARS/system)
+template<typename DegreeOrRadian>
+struct martian
+{
+ typedef DegreeOrRadian units;
+};
+
+// 2: give it also a family
+struct martian_tag;
+
+// 3: register to which coordinate system family it belongs to
+// this must be done in namespace boost::geometry::traits
+namespace boost { namespace geometry { namespace traits
+{
+
+template <typename DegreeOrRadian>
+struct cs_tag<martian<DegreeOrRadian> >
+{
+ typedef martian_tag type;
+};
+
+}}} // namespaces
+
+
+// NOTE: if the next steps would not be here,
+// compiling a distance function call with martian coordinates
+// would result in a MPL assertion
+
+// 4: so register a distance strategy as its default strategy
+namespace boost { namespace geometry { namespace strategy { namespace distance { namespace services
+{
+
+template <typename Point1, typename Point2>
+struct default_strategy<point_tag, Point1, Point2, martian_tag, martian_tag>
+{
+ typedef haversine<Point1, Point2> type;
+};
+
+}}}}} // namespaces
+
+// 5: not worked out. To implement a specific distance strategy for Mars,
+// e.g. with the Mars radius given by default,
+// you will have to implement (/register) several other metafunctions:
+// tag, return_type, similar_type, comparable_type,
+// and structs:
+// get_similar, get_comparable, result_from_distance
+// See e.g. .../boost/geometry/extensions/gis/geographic/strategies/andoyer.hpp
+
+int main()
+{
+ typedef boost::geometry::point
+ <
+ double, 2, martian<boost::geometry::degree>
+ > mars_point;
+
+ // Declare two points
+ // (Source: http://nssdc.gsfc.nasa.gov/planetary/mars_mileage_guide.html)
+ // (Other sources: Wiki and Google give slightly different coordinates, resulting
+ // in other distance, 20 km off)
+ mars_point viking1(-48.23, 22.54); // Viking 1 landing site in Chryse Planitia
+ mars_point pathfinder(-33.55, 19.33); // Pathfinder landing site in Ares Vallis
+
+ double d = boost::geometry::distance(viking1, pathfinder); // Distance in radians on unit-sphere
+
+ // Using the Mars mean radius
+ // (Source: http://nssdc.gsfc.nasa.gov/planetary/factsheet/marsfact.html)
+ std::cout << "Distance between Viking1 and Pathfinder landing sites: "
+ << d * 3389.5 << " km" << std::endl;
+
+ // We would get 832.616 here, same order as the 835 (rounded on 5 km) listed
+ // on the mentioned site
+
+#ifdef OPTIONALLY_ELLIPSOIDAL
+ // Optionally the distance can be calculated more accurate by an Ellipsoidal approach,
+ // giving 834.444 km
+ d = boost::geometry::distance(viking1, pathfinder,
+ boost::geometry::strategy::distance::andoyer<mars_point>
+ (boost::geometry::detail::ellipsoid<double>(3396.2, 3376.2)));
+ std::cout << "Ellipsoidal distance: " << d << " km" << std::endl;
+#endif
+
+ return 0;
+}

Added: sandbox/geometry/libs/geometry/example/c10_custom_cs_example.vcproj
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/example/c10_custom_cs_example.vcproj 2010-10-13 07:33:26 EDT (Wed, 13 Oct 2010)
@@ -0,0 +1,171 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="c10_custom_cs_example"
+ ProjectGUID="{E16737C9-E1F7-450E-9251-B35840FE69B5}"
+ RootNamespace="c10_custom_cs_example"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)\c10_custom_cs_example"
+ ConfigurationType="1"
+ InheritedPropertySheets=".\boost.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ RuntimeLibrary="1"
+ DisableLanguageExtensions="false"
+ UsePrecompiledHeader="0"
+ DebugInformationFormat="1"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)\c10_custom_cs_example"
+ ConfigurationType="1"
+ InheritedPropertySheets=".\boost.vsprops"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ UsePrecompiledHeader="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath=".\c10_custom_cs_example.cpp"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>

Added: sandbox/geometry/libs/geometry/example/c11_custom_cs_transform_example.cpp
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/example/c11_custom_cs_transform_example.cpp 2010-10-13 07:33:26 EDT (Wed, 13 Oct 2010)
@@ -0,0 +1,128 @@
+// Boost.Geometry (aka GGL, Generic Geometry Library)
+//
+// Copyright Barend Gehrels 2010, Geodan, Amsterdam, the Netherlands
+// Use, modification and distribution is subject to the Boost Software License,
+// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+// Example: Custom coordinate system example, using transform
+
+#include <iostream>
+
+#include <boost/geometry/geometry.hpp>
+
+// See also c10_custom_cs_example
+
+// 1: declare, for example two cartesian coordinate systems
+struct cart {};
+struct cart_shifted5 {};
+
+// 2: register to which coordinate system family they belong
+namespace boost { namespace geometry { namespace traits
+{
+
+template<> struct cs_tag<cart> { typedef cartesian_tag type; };
+template<> struct cs_tag<cart_shifted5> { typedef cartesian_tag type; };
+
+}}} // namespaces
+
+
+// 3: sample implementation of a shift
+// to convert coordinate system "cart" to "cart_shirted5"
+template <typename P1, typename P2>
+struct shift
+{
+ inline bool apply(P1 const& p1, P2& p2) const
+ {
+ namespace bg = boost::geometry;
+ bg::set<0>(p2, bg::get<0>(p1) + 5);
+ bg::set<1>(p2, bg::get<1>(p1));
+ return true;
+ }
+};
+
+
+// 4: register the default strategy to transform any cart point to any cart_shifted5 point
+// (note: this will be renamed to "default_strategy" in the near future)
+namespace boost { namespace geometry
+{
+
+template <typename P1, typename P2>
+struct strategy_transform<cartesian_tag, cartesian_tag, cart, cart_shifted5, 2, 2, P1, P2>
+{
+ typedef shift<P1, P2> type;
+};
+
+}} // namespaces
+
+
+// 5: implement a distance strategy between the two different ones
+template <typename P1, typename P2>
+struct shift_and_calc_distance
+{
+ inline double apply(P1 const& p1, P2 const& p2) const
+ {
+ P2 p1_shifted;
+ boost::geometry::transform(p1, p1_shifted);
+ return boost::geometry::distance(p1_shifted, p2);
+ }
+};
+
+// 6: Define point types using this explicitly
+typedef boost::geometry::point<double, 2, cart> point1;
+typedef boost::geometry::point<double, 2, cart_shifted5> point2;
+
+// 7: register the distance strategy
+namespace boost { namespace geometry { namespace strategy { namespace distance { namespace services
+{
+ template <typename Point1, typename Point2>
+ struct tag<shift_and_calc_distance<Point1, Point2> >
+ {
+ typedef strategy_tag_distance_point_point type;
+ };
+
+ template <typename Point1, typename Point2>
+ struct return_type<shift_and_calc_distance<Point1, Point2> >
+ {
+ typedef double type;
+ };
+
+ template <>
+ struct default_strategy<point_tag, point1, point2, cartesian_tag, cartesian_tag>
+ {
+ typedef shift_and_calc_distance<point1, point2> type;
+ };
+
+
+}}}}}
+
+
+
+int main()
+{
+ point1 p1_a(0, 0), p1_b(5, 5);
+ point2 p2_a(2, 2), p2_b(6, 6);
+
+ // Distances run for points on the same coordinate system.
+ // This is possible by default because they are cartesian coordinate systems.
+ double d1 = boost::geometry::distance(p1_a, p1_b);
+ double d2 = boost::geometry::distance(p2_a, p2_b);
+
+ // Transform from a to b:
+ boost::geometry::point<double, 2, cart_shifted5> p1_shifted;
+ boost::geometry::transform(p1_a, p1_shifted);
+
+
+ // Of course this can be calculated now, same CS
+ double d3 = boost::geometry::distance(p1_shifted, p2_a);
+
+
+ // Calculate distance between them. Note that inside distance the
+ // transformation is called.
+ double d4 = boost::geometry::distance(p1_a, p2_a);
+
+ // The result should be the same.
+ std::cout << d3 << " " << d4 << std::endl;
+
+ return 0;
+}

Added: sandbox/geometry/libs/geometry/example/c11_custom_cs_transform_example.vcproj
==============================================================================
--- (empty file)
+++ sandbox/geometry/libs/geometry/example/c11_custom_cs_transform_example.vcproj 2010-10-13 07:33:26 EDT (Wed, 13 Oct 2010)
@@ -0,0 +1,171 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="c11_custom_cs_transform_example"
+ ProjectGUID="{E73E52EC-9BDC-4777-ABB2-DB14FAF27AA5}"
+ RootNamespace="c11_custom_cs_transform_example"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)\c11_custom_cs_transform_example"
+ ConfigurationType="1"
+ InheritedPropertySheets=".\boost.vsprops"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_CONSOLE"
+ RuntimeLibrary="1"
+ DisableLanguageExtensions="false"
+ UsePrecompiledHeader="0"
+ DebugInformationFormat="1"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ GenerateDebugInformation="true"
+ SubSystem="1"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)\c11_custom_cs_transform_example"
+ ConfigurationType="1"
+ InheritedPropertySheets=".\boost.vsprops"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_CONSOLE"
+ UsePrecompiledHeader="0"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ SubSystem="1"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath=".\c11_custom_cs_transform_example.cpp"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>

Modified: sandbox/geometry/libs/geometry/example/custom_examples.sln
==============================================================================
--- sandbox/geometry/libs/geometry/example/custom_examples.sln (original)
+++ sandbox/geometry/libs/geometry/example/custom_examples.sln 2010-10-13 07:33:26 EDT (Wed, 13 Oct 2010)
@@ -20,6 +20,10 @@
 EndProject
 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "c09_custom_fusion_example", "c09_custom_fusion_example.vcproj", "{DA36AD55-E448-43DE-A974-EA765AE3967A}"
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "c10_custom_cs_example", "c10_custom_cs_example.vcproj", "{E16737C9-E1F7-450E-9251-B35840FE69B5}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "c11_custom_cs_transform_example", "c11_custom_cs_transform_example.vcproj", "{E73E52EC-9BDC-4777-ABB2-DB14FAF27AA5}"
+EndProject
 Global
         GlobalSection(SolutionConfigurationPlatforms) = preSolution
                 Debug|Win32 = Debug|Win32
@@ -66,6 +70,14 @@
                 {DA36AD55-E448-43DE-A974-EA765AE3967A}.Debug|Win32.Build.0 = Debug|Win32
                 {DA36AD55-E448-43DE-A974-EA765AE3967A}.Release|Win32.ActiveCfg = Release|Win32
                 {DA36AD55-E448-43DE-A974-EA765AE3967A}.Release|Win32.Build.0 = Release|Win32
+ {E16737C9-E1F7-450E-9251-B35840FE69B5}.Debug|Win32.ActiveCfg = Debug|Win32
+ {E16737C9-E1F7-450E-9251-B35840FE69B5}.Debug|Win32.Build.0 = Debug|Win32
+ {E16737C9-E1F7-450E-9251-B35840FE69B5}.Release|Win32.ActiveCfg = Release|Win32
+ {E16737C9-E1F7-450E-9251-B35840FE69B5}.Release|Win32.Build.0 = Release|Win32
+ {E73E52EC-9BDC-4777-ABB2-DB14FAF27AA5}.Debug|Win32.ActiveCfg = Debug|Win32
+ {E73E52EC-9BDC-4777-ABB2-DB14FAF27AA5}.Debug|Win32.Build.0 = Debug|Win32
+ {E73E52EC-9BDC-4777-ABB2-DB14FAF27AA5}.Release|Win32.ActiveCfg = Release|Win32
+ {E73E52EC-9BDC-4777-ABB2-DB14FAF27AA5}.Release|Win32.Build.0 = Release|Win32
         EndGlobalSection
         GlobalSection(SolutionProperties) = preSolution
                 HideSolutionNode = FALSE


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk