~siretart/ubuntu/utopic/blender/libav10

« back to all changes in this revision

Viewing changes to extern/carve/include/carve/face_impl.hpp

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2012-07-23 08:54:18 UTC
  • mfrom: (14.2.16 sid)
  • mto: (14.2.19 sid)
  • mto: This revision was merged to the branch mainline in revision 42.
  • Revision ID: package-import@ubuntu.com-20120723085418-9foz30v6afaf5ffs
Tags: 2.63a-2
* debian/: Cycles support added (Closes: #658075)
  For now, this top feature has been enabled only
  on [any-amd64 any-i386] architectures because
  of OpenImageIO failing on all others
* debian/: scripts installation path changed
  from /usr/lib to /usr/share:
  + debian/patches/: patchset re-worked for path changing
  + debian/control: "Breaks" field added on yafaray-exporter

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Begin License:
 
2
// Copyright (C) 2006-2011 Tobias Sargeant (tobias.sargeant@gmail.com).
 
3
// All rights reserved.
 
4
//
 
5
// This file is part of the Carve CSG Library (http://carve-csg.com/)
 
6
//
 
7
// This file may be used under the terms of the GNU General Public
 
8
// License version 2.0 as published by the Free Software Foundation
 
9
// and appearing in the file LICENSE.GPL2 included in the packaging of
 
10
// this file.
 
11
//
 
12
// This file is provided "AS IS" with NO WARRANTY OF ANY KIND,
 
13
// INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR
 
14
// A PARTICULAR PURPOSE.
 
15
// End:
 
16
 
 
17
 
 
18
#pragma once
 
19
 
 
20
namespace std {
 
21
  template<unsigned ndim>
 
22
  inline void swap(carve::poly::Face<ndim> &a, carve::poly::Face<ndim> &b) {
 
23
    a.swap(b);
 
24
  }
 
25
}
 
26
 
 
27
namespace carve {
 
28
  namespace poly {
 
29
    template<unsigned ndim>
 
30
    void Face<ndim>::swap(Face<ndim> &other) {
 
31
      std::swap(vertices,    other.vertices);
 
32
      std::swap(edges,       other.edges);
 
33
      std::swap(owner,       other.owner);
 
34
      std::swap(aabb,        other.aabb);
 
35
      std::swap(plane_eqn,   other.plane_eqn);
 
36
      std::swap(manifold_id, other.manifold_id);
 
37
      std::swap(group_id,    other.group_id);
 
38
      std::swap(project,     other.project);
 
39
      std::swap(unproject,   other.unproject);
 
40
    }
 
41
 
 
42
    template<unsigned ndim>
 
43
    template<typename iter_t>
 
44
    Face<ndim> *Face<ndim>::init(const Face<ndim> *base, iter_t vbegin, iter_t vend, bool flipped) {
 
45
      vertices.reserve(std::distance(vbegin, vend));
 
46
 
 
47
      if (flipped) {
 
48
        std::reverse_copy(vbegin, vend, std::back_inserter(vertices));
 
49
        plane_eqn = -base->plane_eqn;
 
50
      } else {
 
51
        std::copy(vbegin, vend, std::back_inserter(vertices));
 
52
        plane_eqn = base->plane_eqn;
 
53
      }
 
54
 
 
55
      edges.clear();
 
56
      edges.resize(nVertices(), NULL);
 
57
 
 
58
      aabb.fit(vertices.begin(), vertices.end(), vec_adapt_vertex_ptr());
 
59
      untag();
 
60
 
 
61
      int da = carve::geom::largestAxis(plane_eqn.N);
 
62
 
 
63
      project = getProjector(plane_eqn.N.v[da] > 0, da);
 
64
      unproject = getUnprojector(plane_eqn.N.v[da] > 0, da);
 
65
 
 
66
      return this;
 
67
    }
 
68
 
 
69
    template<unsigned ndim>
 
70
    template<typename iter_t>
 
71
    Face<ndim> *Face<ndim>::create(iter_t vbegin, iter_t vend, bool flipped) const {
 
72
      return (new Face)->init(this, vbegin, vend, flipped);
 
73
    }
 
74
 
 
75
    template<unsigned ndim>
 
76
    Face<ndim> *Face<ndim>::create(const std::vector<const vertex_t *> &_vertices, bool flipped) const {
 
77
      return (new Face)->init(this, _vertices.begin(), _vertices.end(), flipped);
 
78
    }
 
79
 
 
80
    template<unsigned ndim>
 
81
    Face<ndim> *Face<ndim>::clone(bool flipped) const {
 
82
      return (new Face)->init(this, vertices, flipped);
 
83
    }
 
84
 
 
85
    template<unsigned ndim>
 
86
    void Face<ndim>::getVertexLoop(std::vector<const vertex_t *> &loop) const {
 
87
      loop.resize(nVertices(), NULL);
 
88
      std::copy(vbegin(), vend(), loop.begin());
 
89
    }
 
90
 
 
91
    template<unsigned ndim>
 
92
    const typename Face<ndim>::edge_t *&Face<ndim>::edge(size_t idx) {
 
93
      return edges[idx];
 
94
    }
 
95
 
 
96
    template<unsigned ndim>
 
97
    const typename Face<ndim>::edge_t *Face<ndim>::edge(size_t idx) const {
 
98
      return edges[idx];
 
99
    }
 
100
 
 
101
    template<unsigned ndim>
 
102
    size_t Face<ndim>::nEdges() const {
 
103
      return edges.size();
 
104
    }
 
105
 
 
106
    template<unsigned ndim>
 
107
    const typename Face<ndim>::vertex_t *&Face<ndim>::vertex(size_t idx) {
 
108
      return vertices[idx];
 
109
    }
 
110
 
 
111
    template<unsigned ndim>
 
112
    const typename Face<ndim>::vertex_t *Face<ndim>::vertex(size_t idx) const {
 
113
      return vertices[idx];
 
114
    }
 
115
 
 
116
    template<unsigned ndim>
 
117
    size_t Face<ndim>::nVertices() const {
 
118
      return vertices.size();
 
119
    }
 
120
 
 
121
    template<unsigned ndim>
 
122
    typename Face<ndim>::vector_t Face<ndim>::centroid() const {
 
123
      vector_t c;
 
124
      carve::geom::centroid(vertices.begin(), vertices.end(), vec_adapt_vertex_ptr(), c);
 
125
      return c;
 
126
    }
 
127
 
 
128
    template<unsigned ndim>
 
129
    std::vector<carve::geom::vector<2> > Face<ndim>::projectedVertices() const {
 
130
      p2_adapt_project<ndim> proj = projector();
 
131
      std::vector<carve::geom::vector<2> > result;
 
132
      result.reserve(nVertices());
 
133
      for (size_t i = 0; i < nVertices(); ++i) {
 
134
        result.push_back(proj(vertex(i)->v));
 
135
      }
 
136
      return result;
 
137
    }
 
138
 
 
139
  }
 
140
}