libigl v2.5.0
Loading...
Searching...
No Matches
BinaryWindingNumberOperations.h
Go to the documentation of this file.
1// This file is part of libigl, a simple c++ geometry processing library.
2//
3// Copyright (C) 2015 Qingnan Zhou <qnzhou@gmail.com>
4//
5// This Source Code Form is subject to the terms of the Mozilla Public License
6// v. 2.0. If a copy of the MPL was not distributed with this file, You can
7// obtain one at http://mozilla.org/MPL/2.0/.
8//
9#ifndef IGL_COPYLEFT_CGAL_BINARY_WINDING_NUMBER_OPERATIONS_H
10#define IGL_COPYLEFT_CGAL_BINARY_WINDING_NUMBER_OPERATIONS_H
11
12#include <stdexcept>
13#include "../../igl_inline.h"
14#include "../../MeshBooleanType.h"
15#include <Eigen/Core>
16
17// TODO: This is not written according to libigl style. These should be
18// function handles.
19//
20// Why is this templated on DerivedW
21//
22// These are all generalized to n-ary operations
23namespace igl
24{
25 namespace copyleft
26 {
27 namespace cgal
28 {
30 template <igl::MeshBooleanType Op>
32 public:
33 template<typename DerivedW>
34 typename DerivedW::Scalar operator()(
35 const Eigen::PlainObjectBase<DerivedW>& /*win_nums*/) const {
36 throw (std::runtime_error("not implemented!"));
37 }
38 };
39
41 template <>
43 public:
44 template<typename DerivedW>
45 typename DerivedW::Scalar operator()(
46 const Eigen::PlainObjectBase<DerivedW>& win_nums) const
47 {
48 for(int i = 0;i<win_nums.size();i++)
49 {
50 if(win_nums(i) > 0) return true;
51 }
52 return false;
53 }
54 };
55
57 template <>
59 public:
60 template<typename DerivedW>
61 typename DerivedW::Scalar operator()(
62 const Eigen::PlainObjectBase<DerivedW>& win_nums) const
63 {
64 for(int i = 0;i<win_nums.size();i++)
65 {
66 if(win_nums(i)<=0) return false;
67 }
68 return true;
69 }
70 };
71
73 template <>
75 public:
76 template<typename DerivedW>
77 typename DerivedW::Scalar operator()(
78 const Eigen::PlainObjectBase<DerivedW>& win_nums) const
79 {
80 assert(win_nums.size()>1);
81 // Union of objects 1 through n-1
82 bool union_rest = false;
83 for(int i = 1;i<win_nums.size();i++)
84 {
85 union_rest = union_rest || win_nums(i) > 0;
86 if(union_rest) break;
87 }
88 // Must be in object 0 and not in union of objects 1 through n-1
89 return win_nums(0) > 0 && !union_rest;
90 }
91 };
92
94 template <>
96 public:
97 template<typename DerivedW>
98 typename DerivedW::Scalar operator()(
99 const Eigen::PlainObjectBase<DerivedW>& win_nums) const
100 {
101 // If inside an odd number of objects
102 int count = 0;
103 for(int i = 0;i<win_nums.size();i++)
104 {
105 if(win_nums(i) > 0) count++;
106 }
107 return count % 2 == 1;
108 }
109 };
110
112 template <>
114 public:
115 template<typename DerivedW>
116 typename DerivedW::Scalar operator()(
117 const Eigen::PlainObjectBase<DerivedW>& /*win_nums*/) const {
118 return true;
119 }
120 };
121
127
135
137 template<KeeperType T>
139 public:
140 template<typename DerivedW>
142 const Eigen::PlainObjectBase<DerivedW>& /*win_nums*/) const {
143 throw std::runtime_error("Not implemented");
144 }
145 };
146
148 template<>
150 public:
151 template<typename T>
152 short operator()(T out_w, T in_w) const {
153 if (in_w > 0 && out_w <= 0) return 1;
154 else if (in_w <= 0 && out_w > 0) return -1;
155 else return 0;
156 }
157 };
158
160 template<>
162 public:
163 template<typename T>
164 short operator()(T /*out_w*/, T /*in_w*/) const {
165 return 1;
166 }
167 };
168
171 }
172 }
173}
174
175#endif
DerivedW::Scalar operator()(const Eigen::PlainObjectBase< DerivedW > &win_nums) const
Definition BinaryWindingNumberOperations.h:61
DerivedW::Scalar operator()(const Eigen::PlainObjectBase< DerivedW > &win_nums) const
Definition BinaryWindingNumberOperations.h:77
DerivedW::Scalar operator()(const Eigen::PlainObjectBase< DerivedW > &) const
Definition BinaryWindingNumberOperations.h:116
DerivedW::Scalar operator()(const Eigen::PlainObjectBase< DerivedW > &win_nums) const
Definition BinaryWindingNumberOperations.h:45
DerivedW::Scalar operator()(const Eigen::PlainObjectBase< DerivedW > &win_nums) const
Definition BinaryWindingNumberOperations.h:98
Binary winding number operations.
Definition BinaryWindingNumberOperations.h:31
DerivedW::Scalar operator()(const Eigen::PlainObjectBase< DerivedW > &) const
Definition BinaryWindingNumberOperations.h:34
Keep all policy.
Definition BinaryWindingNumberOperations.h:161
short operator()(T, T) const
Definition BinaryWindingNumberOperations.h:164
Keep inside policy.
Definition BinaryWindingNumberOperations.h:149
short operator()(T out_w, T in_w) const
Definition BinaryWindingNumberOperations.h:152
Filter winding numbers according to keep policy.
Definition BinaryWindingNumberOperations.h:138
short operator()(const Eigen::PlainObjectBase< DerivedW > &) const
Definition BinaryWindingNumberOperations.h:141
BinaryWindingNumberOperations< MESH_BOOLEAN_TYPE_INTERSECT > BinaryIntersect
Definition BinaryWindingNumberOperations.h:123
BinaryWindingNumberOperations< MESH_BOOLEAN_TYPE_UNION > BinaryUnion
Definition BinaryWindingNumberOperations.h:122
KeeperType
Types of Keep policies.
Definition BinaryWindingNumberOperations.h:129
@ KEEP_ALL
Keep everything.
Definition BinaryWindingNumberOperations.h:133
@ KEEP_INSIDE
Keep only inside.
Definition BinaryWindingNumberOperations.h:131
BinaryWindingNumberOperations< MESH_BOOLEAN_TYPE_RESOLVE > BinaryResolve
Definition BinaryWindingNumberOperations.h:126
BinaryWindingNumberOperations< MESH_BOOLEAN_TYPE_XOR > BinaryXor
Definition BinaryWindingNumberOperations.h:125
BinaryWindingNumberOperations< MESH_BOOLEAN_TYPE_MINUS > BinaryMinus
Definition BinaryWindingNumberOperations.h:124
Definition AABB.h:17
@ MESH_BOOLEAN_TYPE_MINUS
A \ B.
Definition MeshBooleanType.h:20
@ MESH_BOOLEAN_TYPE_XOR
A ⊕ B.
Definition MeshBooleanType.h:22
@ MESH_BOOLEAN_TYPE_INTERSECT
A ∩ B.
Definition MeshBooleanType.h:18
@ MESH_BOOLEAN_TYPE_UNION
A ∪ B.
Definition MeshBooleanType.h:16
@ MESH_BOOLEAN_TYPE_RESOLVE
Resolve intersections without removing any non-coplanar faces.
Definition MeshBooleanType.h:24
void count(const Eigen::SparseMatrix< XType > &X, const int dim, Eigen::SparseVector< SType > &S)
Count the number of non-zeros in the columns or rows of a sparse matrix.