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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-01-02 05:55:30 +0400
committerTamito Kajiyama <rd6t-kjym@asahi-net.or.jp>2013-01-02 05:55:30 +0400
commit699da2fb0d9012cef5e45cc1b547a01fd92dbc1c (patch)
treeeb6e3de1f90387af1a2628bbc79d51327e3ac248 /source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp
parent520ab93465d8056bf6d4a4115743daaee4c2fd66 (diff)
Yet another big style clean-up patch by Bastien Montagne, thanks a lot!
Now the code style is acceptable for the merge now, according to Bastien. Thanks again Bastien for having this done! :)
Diffstat (limited to 'source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp')
-rw-r--r--source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp236
1 files changed, 120 insertions, 116 deletions
diff --git a/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp b/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp
index ea57da93347..0e01a70181a 100644
--- a/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp
+++ b/source/blender/freestyle/intern/view_map/CulledOccluderSource.cpp
@@ -1,67 +1,74 @@
-//
-// Filename : CulledOccluderSource.h
-// Author(s) : Alexander Beels
-// Purpose : Class to define a cell grid surrounding
-// the projected image of a scene
-// Date of creation : 2010-12-21
-//
-///////////////////////////////////////////////////////////////////////////////
-
-
-//
-// Copyright (C) : Please refer to the COPYRIGHT file distributed
-// with this source distribution.
-//
-// 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-//
-///////////////////////////////////////////////////////////////////////////////
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * 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.
+ *
+ * The Original Code is Copyright (C) 2010 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/view_map/CulledOccluderSource.cpp
+ * \ingroup freestyle
+ * \brief Class to define a cell grid surrounding the projected image of a scene
+ * \author Alexander Beels
+ * \date 2010-12-21
+ */
#include "CulledOccluderSource.h"
-#include "../geometry/GridHelpers.h"
+
#include "FRS_freestyle.h"
-CulledOccluderSource::CulledOccluderSource (const GridHelpers::Transform& t, WingedEdge& we, ViewMap& viewMap, bool extensiveFEdgeSearch)
- : OccluderSource(t, we),
- rejected(0),
- gridSpaceOccluderProsceniumInitialized(false)
+#include "../geometry/GridHelpers.h"
+
+CulledOccluderSource::CulledOccluderSource(const GridHelpers::Transform& t, WingedEdge& we, ViewMap& viewMap,
+ bool extensiveFEdgeSearch)
+: OccluderSource(t, we), rejected(0), gridSpaceOccluderProsceniumInitialized(false)
{
cullViewEdges(viewMap, extensiveFEdgeSearch);
- // If we have not found any visible FEdges during our cull, then there is nothing
- // to iterate over. Short-circuit everything.
+ // If we have not found any visible FEdges during our cull, then there is nothing to iterate over.
+ // Short-circuit everything.
valid = gridSpaceOccluderProsceniumInitialized;
- if ( valid && ! testCurrent() ) {
+ if (valid && ! testCurrent()) {
next();
}
}
-CulledOccluderSource::~CulledOccluderSource() {
-}
+CulledOccluderSource::~CulledOccluderSource() {}
-bool CulledOccluderSource::testCurrent() {
- if ( valid ) {
+bool CulledOccluderSource::testCurrent()
+{
+ if (valid) {
// The test for gridSpaceOccluderProsceniumInitialized should not be necessary
- return gridSpaceOccluderProsceniumInitialized && GridHelpers::insideProscenium (gridSpaceOccluderProscenium, cachedPolygon);
+ return gridSpaceOccluderProsceniumInitialized &&
+ GridHelpers::insideProscenium(gridSpaceOccluderProscenium, cachedPolygon);
}
return false;
}
-bool CulledOccluderSource::next() {
- while ( OccluderSource::next() ) {
- if ( testCurrent() ) {
+bool CulledOccluderSource::next()
+{
+ while (OccluderSource::next()) {
+ if (testCurrent()) {
++rejected;
return true;
}
@@ -70,17 +77,20 @@ bool CulledOccluderSource::next() {
return false;
}
-void CulledOccluderSource::getOccluderProscenium(real proscenium[4]) {
- for ( unsigned i = 0; i < 4; ++i ) {
+void CulledOccluderSource::getOccluderProscenium(real proscenium[4])
+{
+ for (unsigned int i = 0; i < 4; ++i) {
proscenium[i] = gridSpaceOccluderProscenium[i];
}
}
-static inline real distance2D(const Vec3r & point, const real origin[2]) {
+static inline real distance2D(const Vec3r & point, const real origin[2])
+{
return ::hypot((point[0] - origin[0]), (point[1] - origin[1]));
}
-static inline bool crossesProscenium(real proscenium[4], FEdge *fe) {
+static inline bool crossesProscenium(real proscenium[4], FEdge *fe)
+{
Vec2r min(proscenium[0], proscenium[2]);
Vec2r max(proscenium[1], proscenium[3]);
Vec2r A(fe->vertexA()->getProjectedX(), fe->vertexA()->getProjectedY());
@@ -89,20 +99,20 @@ static inline bool crossesProscenium(real proscenium[4], FEdge *fe) {
return GeomUtils::intersect2dSeg2dArea (min, max, A, B);
}
-static inline bool insideProscenium(real proscenium[4], const Vec3r& point) {
- return ! ( point[0] < proscenium[0] || point[0] > proscenium[1] || point[1] < proscenium[2] || point[1] > proscenium[3] );
+static inline bool insideProscenium(real proscenium[4], const Vec3r& point)
+{
+ return !(point[0] < proscenium[0] || point[0] > proscenium[1] ||
+ point[1] < proscenium[2] || point[1] > proscenium[3]);
}
-void CulledOccluderSource::cullViewEdges(ViewMap& viewMap, bool extensiveFEdgeSearch) {
+void CulledOccluderSource::cullViewEdges(ViewMap& viewMap, bool extensiveFEdgeSearch)
+{
// Cull view edges by marking them as non-displayable.
- // This avoids the complications of trying to delete
- // edges from the ViewMap.
+ // This avoids the complications of trying to delete edges from the ViewMap.
- // Non-displayable view edges will be skipped over during
- // visibility calculation.
+ // Non-displayable view edges will be skipped over during visibility calculation.
- // View edges will be culled according to their position
- // w.r.t. the viewport proscenium (viewport + 5% border,
+ // View edges will be culled according to their position w.r.t. the viewport proscenium (viewport + 5% border,
// or some such).
// Get proscenium boundary for culling
@@ -112,34 +122,30 @@ void CulledOccluderSource::cullViewEdges(ViewMap& viewMap, bool extensiveFEdgeSe
prosceniumOrigin[0] = (viewProscenium[1] - viewProscenium[0]) / 2.0;
prosceniumOrigin[1] = (viewProscenium[3] - viewProscenium[2]) / 2.0;
cout << "Proscenium culling:" << endl;
- cout << "Proscenium: [" << viewProscenium[0] << ", " << viewProscenium[1] << ", " << viewProscenium[2] << ", " << viewProscenium[3] << "]"<< endl;
+ cout << "Proscenium: [" << viewProscenium[0] << ", " << viewProscenium[1] << ", " << viewProscenium[2]
+ << ", " << viewProscenium[3] << "]"<< endl;
cout << "Origin: [" << prosceniumOrigin[0] << ", " << prosceniumOrigin[1] << "]"<< endl;
- // A separate occluder proscenium will also be maintained,
- // starting out the same as the viewport proscenium, and
- // expanding as necessary so that it encompasses the center
- // point of at least one feature edge in each retained view
- // edge.
- // The occluder proscenium will be used later to cull occluding
- // triangles before they are inserted into the Grid.
- // The occluder proscenium starts out the same size as the view
- // proscenium
+ // A separate occluder proscenium will also be maintained, starting out the same as the viewport proscenium, and
+ // expanding as necessary so that it encompasses the center point of at least one feature edge in each
+ // retained view edge.
+ // The occluder proscenium will be used later to cull occluding triangles before they are inserted into the Grid.
+ // The occluder proscenium starts out the same size as the view proscenium
GridHelpers::getDefaultViewProscenium(occluderProscenium);
- // N.B. Freestyle is inconsistent in its use of ViewMap::viewedges_container
- // and vector<ViewEdge*>::iterator. Probably all occurences of vector<ViewEdge*>::iterator
- // should be replaced ViewMap::viewedges_container throughout the code.
+ // XXX Freestyle is inconsistent in its use of ViewMap::viewedges_container and vector<ViewEdge*>::iterator.
+ // Probably all occurences of vector<ViewEdge*>::iterator should be replaced ViewMap::viewedges_container
+ // throughout the code.
// For each view edge
ViewMap::viewedges_container::iterator ve, veend;
- for(ve=viewMap.ViewEdges().begin(), veend=viewMap.ViewEdges().end(); ve!=veend; ve++) {
+ for (ve = viewMap.ViewEdges().begin(), veend = viewMap.ViewEdges().end(); ve != veend; ve++) {
// Overview:
// Search for a visible feature edge
// If none: mark view edge as non-displayable
// Otherwise:
// Find a feature edge with center point inside occluder proscenium.
- // If none exists, find the feature edge with center point
- // closest to viewport origin.
+ // If none exists, find the feature edge with center point closest to viewport origin.
// Expand occluder proscenium to enclose center point.
// For each feature edge, while bestOccluderTarget not found and view edge not visibile
@@ -151,28 +157,27 @@ void CulledOccluderSource::cullViewEdges(ViewMap& viewMap, bool extensiveFEdgeSe
// All ViewEdges start culled
(*ve)->setIsInImage(false);
- // For simple visibility calculation: mark a feature edge
- // that is known to have a center point inside the occluder proscenium.
- // Cull all other feature edges.
+ // For simple visibility calculation: mark a feature edge that is known to have a center point inside
+ // the occluder proscenium. Cull all other feature edges.
do {
// All FEdges start culled
fe->setIsInImage(false);
- // Look for the visible edge that can most easily be included
- // in the occluder proscenium.
- if ( ! bestOccluderTargetFound ) {
- // If center point is inside occluder proscenium,
- if ( insideProscenium(occluderProscenium, fe->center2d()) ) {
+ // Look for the visible edge that can most easily be included in the occluder proscenium.
+ if (!bestOccluderTargetFound) {
+ // If center point is inside occluder proscenium,
+ if (insideProscenium(occluderProscenium, fe->center2d())) {
// Use this feature edge for visibility deterimination
fe->setIsInImage(true);
expandGridSpaceOccluderProscenium(fe);
// Mark bestOccluderTarget as found
bestOccluderTargetFound = true;
bestOccluderTarget = fe;
- } else {
+ }
+ else {
real d = distance2D(fe->center2d(), prosceniumOrigin);
// If center point is closer to viewport origin than current target
- if ( bestOccluderTarget == NULL || d < bestOccluderDistance ) {
+ if (bestOccluderTarget == NULL || d < bestOccluderDistance) {
// Then store as bestOccluderTarget
bestOccluderDistance = d;
bestOccluderTarget = fe;
@@ -181,33 +186,35 @@ void CulledOccluderSource::cullViewEdges(ViewMap& viewMap, bool extensiveFEdgeSe
}
// If feature edge crosses the view proscenium
- if ( ! (*ve)->isInImage() && crossesProscenium(viewProscenium, fe) ) {
+ if (!(*ve)->isInImage() && crossesProscenium(viewProscenium, fe)) {
// Then the view edge will be included in the image
(*ve)->setIsInImage(true);
}
fe = fe->nextEdge();
- } while ( fe != NULL && fe != festart && ! ( bestOccluderTargetFound && (*ve)->isInImage() ) );
+ } while (fe != NULL && fe != festart && !(bestOccluderTargetFound && (*ve)->isInImage()));
// Either we have run out of FEdges, or we already have the one edge we need to determine visibility
// Cull all remaining edges.
- while ( fe != NULL && fe != festart ) {
+ while (fe != NULL && fe != festart) {
fe->setIsInImage(false);
fe = fe->nextEdge();
}
// If bestOccluderTarget was not found inside the occluder proscenium,
// we need to expand the occluder proscenium to include it.
- if ( (*ve)->isInImage() && bestOccluderTarget != NULL && ! bestOccluderTargetFound ) {
+ if ((*ve)->isInImage() && bestOccluderTarget != NULL && ! bestOccluderTargetFound) {
// Expand occluder proscenium to enclose bestOccluderTarget
Vec3r point = bestOccluderTarget->center2d();
- if ( point[0] < occluderProscenium[0] ) {
+ if (point[0] < occluderProscenium[0]) {
occluderProscenium[0] = point[0];
- } else if ( point[0] > occluderProscenium[1] ) {
+ }
+ else if (point[0] > occluderProscenium[1]) {
occluderProscenium[1] = point[0];
}
- if ( point[1] < occluderProscenium[2] ) {
+ if (point[1] < occluderProscenium[2]) {
occluderProscenium[2] = point[1];
- } else if ( point[1] > occluderProscenium[3] ) {
+ }
+ else if (point[1] > occluderProscenium[3]) {
occluderProscenium[3] = point[1];
}
// Use bestOccluderTarget for visibility determination
@@ -225,22 +232,18 @@ void CulledOccluderSource::cullViewEdges(ViewMap& viewMap, bool extensiveFEdgeSe
// For "Normal" or "Fast" style visibility computation only:
- // For more detailed visibility calculation, make a second pass through
- // the view map, marking all feature edges with center points inside
- // the final occluder proscenium. All of these feature edges can be
- // considered during visibility calculation.
-
- // So far we have only found one FEdge per ViewEdge. The "Normal" and
- // "Fast" styles of visibility computation want to consider many
- // FEdges for each ViewEdge.
- // Here we re-scan the view map to find any usable FEdges that we
- // skipped on the first pass, or that have become usable because the
- // occluder proscenium has been expanded since the edge was visited
- // on the first pass.
- if ( extensiveFEdgeSearch ) {
+ // For more detailed visibility calculation, make a second pass through the view map, marking all feature edges
+ // with center points inside the final occluder proscenium. All of these feature edges can be considered during
+ // visibility calculation.
+
+ // So far we have only found one FEdge per ViewEdge. The "Normal" and "Fast" styles of visibility computation
+ // want to consider many FEdges for each ViewEdge.
+ // Here we re-scan the view map to find any usable FEdges that we skipped on the first pass, or that have become
+ // usable because the occluder proscenium has been expanded since the edge was visited on the first pass.
+ if (extensiveFEdgeSearch) {
// For each view edge,
- for(ve=viewMap.ViewEdges().begin(), veend=viewMap.ViewEdges().end(); ve!=veend; ve++) {
- if ( ! (*ve)->isInImage() ) {
+ for (ve = viewMap.ViewEdges().begin(), veend = viewMap.ViewEdges().end(); ve != veend; ve++) {
+ if (!(*ve)->isInImage()) {
continue;
}
// For each feature edge,
@@ -248,30 +251,31 @@ void CulledOccluderSource::cullViewEdges(ViewMap& viewMap, bool extensiveFEdgeSe
FEdge *fe = festart;
do {
// If not (already) visible and center point inside occluder proscenium,
- if ( ! fe->isInImage() && insideProscenium(occluderProscenium, fe->center2d()) ) {
+ if (!fe->isInImage() && insideProscenium(occluderProscenium, fe->center2d())) {
// Use the feature edge for visibility determination
fe->setIsInImage(true);
expandGridSpaceOccluderProscenium(fe);
}
fe = fe->nextEdge();
- } while ( fe != NULL && fe != festart );
+ } while (fe != NULL && fe != festart);
}
}
// Up until now, all calculations have been done in camera space.
- // However, the occluder source's iteration and the grid that consumes the occluders
- // both work in gridspace, so we need a version of the occluder proscenium in gridspace.
+ // However, the occluder source's iteration and the grid that consumes the occluders both work in gridspace,
+ // so we need a version of the occluder proscenium in gridspace.
// Set the gridspace occlude proscenium
}
-void CulledOccluderSource::expandGridSpaceOccluderProscenium(FEdge* fe) {
- if ( gridSpaceOccluderProsceniumInitialized ) {
- GridHelpers::expandProscenium (gridSpaceOccluderProscenium, transform(fe->center3d()));
- } else {
+void CulledOccluderSource::expandGridSpaceOccluderProscenium(FEdge *fe)
+{
+ if (gridSpaceOccluderProsceniumInitialized) {
+ GridHelpers::expandProscenium(gridSpaceOccluderProscenium, transform(fe->center3d()));
+ }
+ else {
const Vec3r& point = transform(fe->center3d());
gridSpaceOccluderProscenium[0] = gridSpaceOccluderProscenium[1] = point[0];
gridSpaceOccluderProscenium[2] = gridSpaceOccluderProscenium[3] = point[1];
gridSpaceOccluderProsceniumInitialized = true;
}
}
-