Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added .clang-format and formatted example file #19

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#
# This file shall be used to autoformat the source code for vcglib
# more info on clang-format: https://clang.llvm.org/docs/ClangFormat.html
#
---
Language: Cpp
# BasedOnStyle: LLVM
AccessModifierOffset: -2
AlignAfterOpenBracket: false
AlignEscapedNewlinesLeft: true
AlignOperands: true
AlignTrailingComments: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: false
AllowShortFunctionsOnASingleLine: All
AlwaysBreakAfterDefinitionReturnType: false
AlwaysBreakTemplateDeclarations: true
AlwaysBreakBeforeMultilineStrings: true
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BinPackParameters: true
BinPackArguments: true
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
DerivePointerAlignment: false
ExperimentalAutoDetectBinPacking: false
IndentCaseLabels: true
IndentWrappedFunctionNames: false
IndentFunctionDeclarationAfterType: false
MaxEmptyLinesToKeep: 1
KeepEmptyLinesAtTheStartOfBlocks: true
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PenaltyBreakBeforeFirstCallParameter: 19
PenaltyBreakComment: 300
PenaltyBreakString: 1000
PenaltyBreakFirstLessLess: 120
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 60
PointerAlignment: Left
SpacesBeforeTrailingComments: 1
Cpp11BracedListStyle: true
Standard: Cpp11
IndentWidth: 4
TabWidth: 2
UseTab: Never
BreakBeforeBraces: Allman
SpacesInParentheses: false
SpacesInSquareBrackets: false
SpacesInAngles: false
SpaceInEmptyParentheses: false
SpacesInCStyleCastParentheses: false
SpaceAfterCStyleCast: false
SpacesInContainerLiterals: true
SpaceBeforeAssignmentOperators: true
ContinuationIndentWidth: 2
CommentPragmas: '^ IWYU pragma:'
ForEachMacros: [ foreach, Q_FOREACH, BOOST_FOREACH ]
SpaceBeforeParens: ControlStatements
DisableFormat: false
SortIncludes: false
# FixNamespaceComments: true
...
157 changes: 79 additions & 78 deletions vcg/complex/algorithms/parametrization/uv_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* 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. *
Expand All @@ -21,12 +21,13 @@
* *
****************************************************************************/

#ifndef VCG_UV_UTILS
#define VCG_UV_UTILS
#ifndef VCG_COMPLEX_ALGORITHMS_PARAMETRIZATION_UV_UTILS_H
#define VCG_COMPLEX_ALGORITHMS_PARAMETRIZATION_UV_UTILS_H


namespace vcg {
namespace tri{
namespace vcg
{
namespace tri
{
template <class MeshType>
class UV_Utils
{
Expand All @@ -38,132 +39,132 @@ class UV_Utils
typedef typename MeshType::FaceIterator FaceIterator;
typedef typename vcg::Point2<ScalarType> UVCoordType;

public:
///calculate the BBox in UV space
static vcg::Box2<ScalarType> PerWedgeUVBox(MeshType &m)
public:
/// calculate the BBox in UV space
static vcg::Box2<ScalarType> PerWedgeUVBox(MeshType& m)
{
vcg::Box2<ScalarType> UVBox;
FaceIterator fi;
for (fi=m.face.begin();fi!=m.face.end();fi++)
for (fi = m.face.begin(); fi != m.face.end(); fi++)
{
if ((*fi).IsD()) continue;
for (int i=0;i<3;i++)
UVBox.Add((*fi).WT(i).P());
if (fi->IsD()) continue;
for (int i = 0; i < 3; i++)
UVBox.Add(fi->WT(i).P());
}
return UVBox;
}

///calculate the BBox in UV space
static vcg::Box2<ScalarType> PerVertUVBox(MeshType &m)
/// calculate the BBox in UV space
static vcg::Box2<ScalarType> PerVertUVBox(MeshType& m)
{
vcg::Box2<ScalarType> UVBox;
VertexIterator vi;
for (vi=m.vert.begin();vi!=m.vert.end();vi++)
for (vi = m.vert.begin(); vi != m.vert.end(); vi++)
{
if ((*vi).IsD()) continue;
UVBox.Add((*vi).T().P());
if (vi->IsD()) continue;
UVBox.Add(vi->T().P());
}
return UVBox;
}

void PerWedgeMakeUnitaryUV(MeshType &m)
void PerWedgeMakeUnitaryUV(MeshType& m)
{
vcg::Box2<typename MeshType::ScalarType> UVBox = PerWedgeUVBox(m);

typename MeshType::FaceIterator fi;
Point2f boxSize(UVBox.max-UVBox.min);
for (fi=m.face.begin();fi!=m.face.end();fi++)
Point2f boxSize(UVBox.max - UVBox.min);
for (fi = m.face.begin(); fi != m.face.end(); fi++)
{
if ((*fi).IsD()) continue;
for (int i=0;i<3;i++)
if (fi->IsD()) continue;
for (int i = 0; i < 3; i++)
{
(*fi).WT(i).U() = ((*fi).WT(i).U()-UVBox.min[0])/boxSize[0] ;
(*fi).WT(i).V() = ((*fi).WT(i).V()-UVBox.min[1])/boxSize[1] ;
fi->WT(i).U() = (fi->WT(i).U() - UVBox.min[0]) / boxSize[0];
fi->WT(i).V() = (fi->WT(i).V() - UVBox.min[1]) / boxSize[1];
}
}
}
///transform curvature to UV space
static UVCoordType Coord3DtoUV(FaceType &f,const CoordType &dir)
/// transform curvature to UV space
static UVCoordType Coord3DtoUV(FaceType& f, const CoordType& dir)
{
///then transform to UV
CoordType bary3d=(f.P(0)+f.P(1)+f.P(2))/3.0;
UVCoordType baryUV=(f.WT(0).P()+f.WT(1).P()+f.WT(2).P())/3.0;
CoordType dir3d=bary3d+dir;
/// then transform to UV
CoordType bary3d = (f.P(0) + f.P(1) + f.P(2)) / 3.0;
UVCoordType baryUV = (f.WT(0).P() + f.WT(1).P() + f.WT(2).P()) / 3.0;
CoordType dir3d = bary3d + dir;
CoordType baryCoordsUV;
vcg::InterpolationParameters<FaceType,ScalarType>(f,dir3d,baryCoordsUV);
UVCoordType dirUV=baryCoordsUV.X()*f.WT(0).P()+
baryCoordsUV.Y()*f.WT(1).P()+
baryCoordsUV.Z()*f.WT(2).P()-baryUV;
vcg::InterpolationParameters<FaceType, ScalarType>(f, dir3d, baryCoordsUV);
UVCoordType dirUV = baryCoordsUV.X() * f.WT(0).P() + baryCoordsUV.Y() * f.WT(1).P()
+ baryCoordsUV.Z() * f.WT(2).P() - baryUV;
dirUV.Normalize();
return dirUV;
}

static void GloballyMirrorX(MeshType &m)
static void GloballyMirrorX(MeshType& m)
{
vcg::Box2<ScalarType> BBuv=PerVertUVBox(m);
ScalarType Xmin=BBuv.min.X();
ScalarType Xmax=BBuv.max.X();
ScalarType XAv=(Xmax+Xmin)/2;
vcg::Box2<ScalarType> BBuv = PerVertUVBox(m);
ScalarType Xmin = BBuv.min.X();
ScalarType Xmax = BBuv.max.X();
ScalarType XAv = (Xmax + Xmin) / 2;
VertexIterator vi;
for (vi=m.vert.begin();vi!=m.vert.end();vi++)
for (vi = m.vert.begin(); vi != m.vert.end(); vi++)
{
ScalarType distAV=(*vi).T().P().X()-XAv;
(*vi).T().P().X()=XAv-distAV;
ScalarType distAV = vi->T().P().X() - XAv;
vi->T().P().X() = XAv - distAV;
}
}

static void LaplacianUVVert(MeshType &m,bool fix_borders=false,int steps=3)
static void LaplacianUVVert(MeshType& m, bool fix_borders = false, int steps = 3)
{
FaceIterator fi;
for (int s=0;s<steps;s++)
for (int s = 0; s < steps; s++)
{
std::vector<int> num(m.vert.size(),0);
std::vector<UVCoordType> UVpos(m.vert.size(),UVCoordType(0,0));
for (fi=m.face.begin();fi!=m.face.end();fi++)
std::vector<int> num(m.vert.size(), 0);
std::vector<UVCoordType> UVpos(m.vert.size(), UVCoordType(0, 0));
for (fi = m.face.begin(); fi != m.face.end(); fi++)
{
for (int j=0;j<3;j++)
for (int j = 0; j < 3; j++)
{
VertexType *v0=(*fi).V(0);
VertexType *v1=(*fi).V1(0);
VertexType *v2=(*fi).V2(0);
assert(v0!=v1);
assert(v1!=v2);
assert(v0!=v2);
UVCoordType uv1=v1->T().P();
UVCoordType uv2=v2->T().P();
int index=v0-&(m.vert[0]);
num[index]+=2;
UVpos[index]+=uv1;
UVpos[index]+=uv2;
VertexType* v0 = fi->V(0);
VertexType* v1 = fi->V1(0);
VertexType* v2 = fi->V2(0);
assert(v0 != v1);
assert(v1 != v2);
assert(v0 != v2);
UVCoordType uv1 = v1->T().P();
UVCoordType uv2 = v2->T().P();
int index = v0 - &(m.vert[0]);
num[index] += 2;
UVpos[index] += uv1;
UVpos[index] += uv2;
}
}
VertexIterator vi;
for (int i=0;i<m.vert.size();i++)

for (int i = 0; i < m.vert.size(); i++)
{
if ((fix_borders)&&(m.vert[i].IsB()))continue;
if (num[i]==0)continue;
m.vert[i].T().P()=UVpos[i]/(ScalarType)num[i];
if (fix_borders && m.vert[i].IsB()) continue;
if (num[i] == 0) continue;
m.vert[i].T().P() = UVpos[i] / (ScalarType)num[i];
}
}
}

static void CopyVertUVWedge(MeshType &m)
static void CopyVertUVWedge(MeshType& m)
{
for (size_t i=0;i<m.face.size();i++)
for (size_t j=0;j<3;j++)
m.face[i].WT(j).P()=m.face[i].V(j)->T().P();
for (size_t i = 0; i < m.face.size(); i++)
for (size_t j = 0; j < 3; j++)
m.face[i].WT(j).P() = m.face[i].V(j)->T().P();
}

static void CopyWedgeVertUV(MeshType &m,bool onlyS=false)
static void CopyWedgeVertUV(MeshType& m, bool onlyS = false)
{
for (size_t i=0;i<m.face.size();i++)
for (size_t i = 0; i < m.face.size(); i++)
{
if ((onlyS)&&(!m.face[i].IsS()))continue;
for (int j=0;j<3;j++)
m.face[i].V(j)->T().P()=m.face[i].WT(j).P();
if (onlyS && !m.face[i].IsS()) continue;
for (int j = 0; j < 3; j++)
m.face[i].V(j)->T().P() = m.face[i].WT(j).P();
}
}
};
} //End Namespace Tri
} // End Namespace vcg
#endif

} // end namespace tri
} // end namespace vcg
#endif // VCG_COMPLEX_ALGORITHMS_PARAMETRIZATION_UV_UTILS_H