Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Interface1D.h « view_map « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: ab489bff4c9be269fd85e10ac8b9f0a1368d662e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
/*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#ifndef __FREESTYLE_INTERFACE_1D_H__
#define __FREESTYLE_INTERFACE_1D_H__

/** \file
 * \ingroup freestyle
 * \brief Interface 1D and related tools definitions
 */

#include <float.h>
#include <iostream>
#include <string>

#include "Functions0D.h"

#include "../system/Id.h"
#include "../system/Precision.h"

#include "../winged_edge/Nature.h"

#ifdef WITH_CXX_GUARDEDALLOC
#  include "MEM_guardedalloc.h"
#endif

using namespace std;

namespace Freestyle {

// Integration method
/*! The different integration methods that can be invoked to integrate into a single value the set
 * of values obtained from each 0D element of a 1D element.
 */
typedef enum {
  MEAN, /*!< The value computed for the 1D element is the mean of the values obtained for the 0D
           elements.*/
  MIN,  /*!< The value computed for the 1D element is the minimum of the values obtained for the 0D
           elements.*/
  MAX,  /*!< The value computed for the 1D element is the maximum of the values obtained for the 0D
           elements.*/
  FIRST, /*!< The value computed for the 1D element is the first of the values obtained for the 0D
            elements.*/
  LAST,  /*!< The value computed for the 1D element is the last of the values obtained for the 0D
            elements.*/
} IntegrationType;

/*! Returns a single value from a set of values evaluated at each 0D element of this 1D element.
 * \param fun:
 *    The UnaryFunction0D used to compute a value at each Interface0D.
 * \param it:
 *    The Interface0DIterator used to iterate over the 0D elements of this 1D element. The
 * integration will occur over the 0D elements starting from the one pointed by it. \param it_end:
 *    The Interface0DIterator pointing the end of the 0D elements of the 1D element.
 * \param integration_type:
 *    The integration method used to compute a single value from a set of values.
 * \return the single value obtained for the 1D element.
 */
template<class T>
T integrate(UnaryFunction0D<T> &fun,
            Interface0DIterator it,
            Interface0DIterator it_end,
            IntegrationType integration_type = MEAN)
{
  T res;
  unsigned size;
  switch (integration_type) {
    case MIN:
      fun(it);
      res = fun.result;
      ++it;
      for (; !it.isEnd(); ++it) {
        fun(it);
        if (fun.result < res) {
          res = fun.result;
        }
      }
      break;
    case MAX:
      fun(it);
      res = fun.result;
      ++it;
      for (; !it.isEnd(); ++it) {
        fun(it);
        if (fun.result > res) {
          res = fun.result;
        }
      }
      break;
    case FIRST:
      fun(it);
      res = fun.result;
      break;
    case LAST:
      fun(--it_end);
      res = fun.result;
      break;
    case MEAN:
    default:
      fun(it);
      res = fun.result;
      ++it;
      for (size = 1; !it.isEnd(); ++it, ++size) {
        fun(it);
        res += fun.result;
      }
      res /= (size ? size : 1);
      break;
  }
  return res;
}

//
// Interface1D
//
//////////////////////////////////////////////////

/*! Base class for any 1D element. */
class Interface1D {
 public:
  /*! Default constructor */
  Interface1D()
  {
    _timeStamp = 0;
  }

  /*! Destructor */
  virtual ~Interface1D(){};

  /*! Returns the string "Interface1D". */
  virtual string getExactTypeName() const
  {
    return "Interface1D";
  }

  // Iterator access

  /*! Returns an iterator over the Interface1D vertices, pointing to the first vertex. */
  virtual Interface0DIterator verticesBegin();

  /*! Returns an iterator over the Interface1D vertices, pointing after the last vertex. */
  virtual Interface0DIterator verticesEnd();

  /*! Returns an iterator over the Interface1D points, pointing to the first point. The difference
   * with verticesBegin() is that here we can iterate over points of the 1D element at a any given
   * sampling. Indeed, for each iteration, a virtual point is created.
   *
   * \param t: The sampling with which we want to iterate over points of this 1D element.
   */
  virtual Interface0DIterator pointsBegin(float t = 0.0f);

  /*! Returns an iterator over the Interface1D points, pointing after the last point. The
   * difference with verticesEnd() is that here we can iterate over points of the 1D element at a
   * any given sampling. Indeed, for each iteration, a virtual point is created.
   *
   * \param t: The sampling with which we want to iterate over points of this 1D element.
   */
  virtual Interface0DIterator pointsEnd(float t = 0.0f);

  // Data access methods

  /*! Returns the 2D length of the 1D element. */
  virtual real getLength2D() const;

  /*! Returns the Id of the 1D element. */
  virtual Id getId() const;

  // FIXME: ce truc n'a rien a faire la...(c une requete complexe qui doit etre ds les Function1D)
  /*! Returns the nature of the 1D element. */
  virtual Nature::EdgeNature getNature() const;

  /*! Returns the time stamp of the 1D element. Mainly used for selection. */
  virtual unsigned getTimeStamp() const
  {
    return _timeStamp;
  }

  /*! Sets the time stamp for the 1D element. */
  inline void setTimeStamp(unsigned iTimeStamp)
  {
    _timeStamp = iTimeStamp;
  }

 protected:
  unsigned _timeStamp;

#ifdef WITH_CXX_GUARDEDALLOC
  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Interface1D")
#endif
};

} /* namespace Freestyle */

#endif  // __FREESTYLE_INTERFACE_1D_H__