Merge remote-tracking branch 'origin/master' into performance_tuning

This commit is contained in:
Hans-Christian Ebke
2016-03-24 12:59:35 +01:00
17 changed files with 219 additions and 110 deletions

View File

@@ -473,7 +473,7 @@ class VectorT {
/// compute L1 (Manhattan) norm
Scalar l1_norm() const {
return std::accumulate(
values_.cbegin() + 1, values_.end(), values_[0]);
values_.cbegin() + 1, values_.cend(), values_[0]);
}
/// compute l8_norm
@@ -523,7 +523,7 @@ class VectorT {
/// return absolute arithmetic mean
Scalar mean_abs() const {
return std::accumulate(values_.cbegin() + 1, values_.end(),
return std::accumulate(values_.cbegin() + 1, values_.cend(),
std::abs(values_[0]),
[](const Scalar &l, const Scalar &r) {
return l + std::abs(r);

View File

@@ -1,80 +0,0 @@
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2015, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= */
//=============================================================================
//
// CLASS VectorDimensionsT
//
//=============================================================================
#ifndef DOXYGEN
#ifndef OPENMESH_VECTOR_DIMENSIONS_HH
#define OPENMESH_VECTOR_DIMENSIONS_HH
//== INCLUDES =================================================================
#include <OpenMesh/Core/System/config.h>
#include <OpenMesh/Core/Geometry/VectorT.hh>
//== NAMESPACES ===============================================================
namespace OpenMesh {
//== CLASS DEFINITION =========================================================
template<typename Vector>
struct VectorDimensionsT {};
template<typename Scalar, int Dim>
struct VectorDimensionsT< OpenMesh::VectorT<Scalar, Dim> > {
enum {
value = Dim
};
};
//=============================================================================
} // namespace OpenMesh
//=============================================================================
#endif // OPENMESH_VECTOR_DIMENSIONS_HH defined
//=============================================================================
#endif // DOXYGEN

View File

@@ -106,6 +106,9 @@ public:
// add texture coordinates per face, _vh references the first texcoord
virtual void add_face_texcoords( FaceHandle _fh, VertexHandle _vh, const std::vector<Vec2f>& _face_texcoords) = 0;
// add texture 3d coordinates per face, _vh references the first texcoord
virtual void add_face_texcoords( FaceHandle _fh, VertexHandle _vh, const std::vector<Vec3f>& _face_texcoords) = 0;
// Set the texture index for a face
virtual void set_face_texindex( FaceHandle _fh, int _texId ) = 0;
@@ -133,6 +136,12 @@ public:
// set vertex texture coordinate
virtual void set_texcoord(HalfedgeHandle _heh, const Vec2f& _texcoord) = 0;
// set 3d vertex texture coordinate
virtual void set_texcoord(VertexHandle _vh, const Vec3f& _texcoord) = 0;
// set 3d vertex texture coordinate
virtual void set_texcoord(HalfedgeHandle _heh, const Vec3f& _texcoord) = 0;
// set edge color
virtual void set_color(EdgeHandle _eh, const Vec3uc& _color) = 0;

View File

@@ -90,6 +90,7 @@ public:
typedef typename Mesh::Normal Normal;
typedef typename Mesh::Color Color;
typedef typename Mesh::TexCoord2D TexCoord2D;
typedef typename Mesh::TexCoord3D TexCoord3D;
typedef std::vector<VertexHandle> VHandles;
@@ -217,6 +218,19 @@ public:
mesh_.set_texcoord2D(_heh, vector_cast<TexCoord2D>(_texcoord));
}
virtual void set_texcoord(VertexHandle _vh, const Vec3f& _texcoord)
{
if (mesh_.has_vertex_texcoords3D())
mesh_.set_texcoord3D(_vh, vector_cast<TexCoord3D>(_texcoord));
}
virtual void set_texcoord(HalfedgeHandle _heh, const Vec3f& _texcoord)
{
if (mesh_.has_halfedge_texcoords3D())
mesh_.set_texcoord3D(_heh, vector_cast<TexCoord3D>(_texcoord));
}
// edge attributes
virtual void set_color(EdgeHandle _eh, const Vec4uc& _color)
@@ -292,6 +306,23 @@ public:
}
}
virtual void add_face_texcoords( FaceHandle _fh, VertexHandle _vh, const std::vector<Vec3f>& _face_texcoords)
{
// get first halfedge handle
HalfedgeHandle cur_heh = mesh_.halfedge_handle(_fh);
HalfedgeHandle end_heh = mesh_.prev_halfedge_handle(cur_heh);
// find start heh
while( mesh_.to_vertex_handle(cur_heh) != _vh && cur_heh != end_heh )
cur_heh = mesh_.next_halfedge_handle( cur_heh);
for(unsigned int i=0; i<_face_texcoords.size(); ++i)
{
set_texcoord( cur_heh, _face_texcoords[i]);
cur_heh = mesh_.next_halfedge_handle( cur_heh);
}
}
virtual void set_face_texindex( FaceHandle _fh, int _texId ) {
if ( mesh_.has_face_texture_index() ) {
mesh_.set_texture_index(_fh , _texId);

View File

@@ -290,13 +290,13 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
std::string line;
std::string keyWrd;
float x, y, z, u, v;
float x, y, z, u, v, w;
float r, g, b;
BaseImporter::VHandles vhandles;
std::vector<Vec3f> normals;
std::vector<Vec3f> colors;
std::vector<Vec2f> texcoords;
std::vector<Vec2f> face_texcoords;
std::vector<Vec3f> texcoords3d, face_texcoords3d;
std::vector<Vec2f> texcoords, face_texcoords;
std::vector<VertexHandle> vertexHandles;
std::string matname;
@@ -413,11 +413,16 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
// Can be used for both!
fileOptions += Options::VertexTexCoord;
fileOptions += Options::FaceTexCoord;
// try to read the w component as it is optional
stream >> w;
if ( !stream.fail() )
texcoords3d.push_back(OpenMesh::Vec3f(u, v, w));
}
}else{
omerr() << "Only single 2D texture coordinate per vertex"
omerr() << "Only single 2D or 3D texture coordinate per vertex"
<< "allowed!" << std::endl;
return false;
}
@@ -553,6 +558,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
if (!texcoords.empty() && (unsigned int) (value - 1) < texcoords.size()) {
// Obj counts from 1 and not zero .. array counts from zero therefore -1
_bi.set_texcoord(vhandles.back(), texcoords[value - 1]);
if(!texcoords3d.empty() && (unsigned int) (value -1) < texcoords3d.size())
_bi.set_texcoord(vhandles.back(), texcoords3d[value - 1]);
} else {
omerr() << "Error setting Texture coordinates" << std::endl;
}
@@ -563,6 +570,8 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
if (!texcoords.empty() && (unsigned int) (value - 1) < texcoords.size()) {
face_texcoords.push_back( texcoords[value-1] );
if(!texcoords3d.empty() && (unsigned int) (value -1) < texcoords3d.size())
face_texcoords3d.push_back( texcoords3d[value-1] );
} else {
omerr() << "Error setting Texture coordinates" << std::endl;
}
@@ -609,7 +618,10 @@ read(std::istream& _in, BaseImporter& _bi, Options& _opt)
fh = _bi.add_face(faceVertices);
if (!vhandles.empty() && fh.is_valid() )
{
_bi.add_face_texcoords(fh, vhandles[0], face_texcoords);
_bi.add_face_texcoords(fh, vhandles[0], face_texcoords3d);
}
if ( !matname.empty() )
{

View File

@@ -1275,7 +1275,19 @@ bool _PLYReader_::can_u_read(std::istream& _is) const {
// As the binary data is directy after the end_header keyword
// and the stream removes too many bytes, seek back to the right position
if (options_.is_binary()) {
_is.seekg(streamPos + 12);
_is.seekg(streamPos);
char c1 = 0;
char c2 = 0;
_is.get(c1);
_is.get(c2);
if (c1 == 0x0D && c2 == 0x0A) {
_is.seekg(streamPos + 14);
}
else {
_is.seekg(streamPos + 12);
}
}
return true;

View File

@@ -118,7 +118,7 @@ write(const std::string& _filename, BaseExporter& _be, Options _opt, std::stream
dot = _filename.find_last_of(".");
if(dot != std::string::npos)
objName_ = objName_.substr(0,dot-1);
objName_ = objName_.substr(0,dot);
}
bool result = write(out, _be, _opt, _precision);
@@ -184,7 +184,7 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const
for (size_t i=0; i < materialA_.size(); i++){
_out << "newmtl " << "mat" << i << '\n';
_out << "Ka 0.5000 0.5000 0.5000" << '\n';
_out << "Kd " << materialA_[i][0] << materialA_[i][1] << materialA_[i][2] << '\n';;
_out << "Kd " << materialA_[i][0] << ' ' << materialA_[i][1] << ' ' << materialA_[i][2] << '\n';
_out << "Tr " << materialA_[i][3] << '\n';
_out << "illum 1" << '\n';
}
@@ -192,7 +192,7 @@ writeMaterial(std::ostream& _out, BaseExporter& _be, Options _opt) const
for (size_t i=0; i < material_.size(); i++){
_out << "newmtl " << "mat" << i << '\n';
_out << "Ka 0.5000 0.5000 0.5000" << '\n';
_out << "Kd " << material_[i][0] << material_[i][1] << material_[i][2] << '\n';;
_out << "Kd " << material_[i][0] << ' ' << material_[i][1] << ' ' << material_[i][2] << '\n';
_out << "illum 1" << '\n';
}

View File

@@ -99,7 +99,7 @@ public:
void __decrement() { --idx_; }
void __increment(int amount) { idx_ += amount; }
void __decrement(int amount) { idx_ += amount; }
void __decrement(int amount) { idx_ -= amount; }
private:

View File

@@ -61,9 +61,9 @@
#include <OpenMesh/Core/Mesh/PolyMeshT.hh>
#include <OpenMesh/Core/Geometry/LoopSchemeMaskT.hh>
#include <OpenMesh/Core/Geometry/VectorDimensionsT.hh>
#include <OpenMesh/Core/Utils/GenProg.hh>
#include <OpenMesh/Core/Utils/vector_cast.hh>
#include <OpenMesh/Core/Utils/vector_traits.hh>
#include <OpenMesh/Core/System/omstream.hh>
#include <vector>
@@ -102,7 +102,7 @@ typename PolyMeshT<Kernel>::Normal
PolyMeshT<Kernel>::calc_face_normal(FaceHandle _fh) const
{
return calc_face_normal_impl(_fh, typename GenProg::IF<
VectorDimensionsT<PolyMeshT<Kernel>::Point>::value == 3,
vector_traits<PolyMeshT<Kernel>::Point>::size_ == 3,
PointIs3DTag,
PointIsNot3DTag
>::Result());
@@ -169,7 +169,7 @@ calc_face_normal(const Point& _p0,
const Point& _p2) const
{
return calc_face_normal_impl(_p0, _p1, _p2, typename GenProg::IF<
VectorDimensionsT<PolyMeshT<Kernel>::Point>::value == 3,
vector_traits<PolyMeshT<Kernel>::Point>::size_ == 3,
PointIs3DTag,
PointIsNot3DTag
>::Result());