Changed OpenMesh directory structure

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@106 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
Jan Möbius
2009-04-30 12:41:50 +00:00
parent 6b48ca6090
commit ea844d6788
310 changed files with 20 additions and 1 deletions

View File

@@ -0,0 +1,18 @@
#== SYSTEM PART -- DON'T TOUCH ==============================================
include $(ACGMAKE)/Config
#==============================================================================
CXX_CFLAGS += -DQT_THREAD_SUPPORT
SUBDIRS = $(call find-subdirs)
PACKAGES := qt4 glut opengl
PROJ_LIBS := OpenMesh/Core OpenMesh/Tools
MODULES := moc4 cxx
#== SYSTEM PART -- DON'T TOUCH ==============================================
include $(ACGMAKE)/Rules
#==============================================================================

View File

@@ -0,0 +1,225 @@
#include <iostream>
#include <fstream>
#include <map>
#include <OpenMesh/Core/IO/MeshIO.hh>
#include <OpenMesh/Core/IO/BinaryHelper.hh>
#include <OpenMesh/Core/Utils/Endian.hh>
#include "ServerSideVDPM.hh"
using OpenMesh::VDPM::VHierarchyNode;
using OpenMesh::VDPM::VHierarchyNodeIndex;
using OpenMesh::VDPM::VHierarchyNodeHandle;
void
ServerSideVDPM::
clear()
{
points_.clear();
triangles_.clear();
vhierarchy_.clear();
n_base_vertices_ = 0;
n_base_faces_ = 0;
n_details_ = 0;
}
OpenMesh::VertexHandle
ServerSideVDPM::
add_vertex(const OpenMesh::Vec3f &p)
{
points_.push_back(p);
return OpenMesh::VertexHandle(points_.size() - 1);
}
OpenMesh::FaceHandle
ServerSideVDPM::
add_face(const unsigned int _triangle[3])
{
OpenMesh::Vec3ui fvi;
fvi[0] = _triangle[0];
fvi[1] = _triangle[1];
fvi[2] = _triangle[2];
triangles_.push_back(fvi);
return OpenMesh::FaceHandle(triangles_.size() - 1);
}
void
ServerSideVDPM::
vhierarchy_roots(VHierarchyNodeHandleContainer &roots) const
{
unsigned int i;
roots.clear();
for (i=0; i<n_base_vertices_; ++i)
{
roots.push_back(VHierarchyNodeHandle(i));
}
}
bool
ServerSideVDPM::
open_vd_prog_mesh(const char *_filename)
{
unsigned int i;
unsigned int value;
unsigned int fvi[3];
char fileformat[16];
OpenMesh::Vec3f p, normal;
float radius, sin_square, mue_square, sigma_square;
OpenMesh::VertexHandle vertex_handle;
VHierarchyNodeIndex
node_index, lchild_node_index, rchild_node_index,
fund_lcut_index, fund_rcut_index;
VHierarchyNodeHandle
node_handle, lchild_handle, rchild_handle;
std::map<VHierarchyNodeIndex, VHierarchyNodeHandle> index2handle_map;
std::ifstream ifs(_filename, std::ios::binary);
if (!ifs)
{
std::cerr << "read error\n";
return false;
}
//
bool swap = OpenMesh::Endian::local() != OpenMesh::Endian::LSB;
// read header
ifs.read(fileformat, 10); fileformat[10] = '\0';
if (std::string(fileformat) != std::string("VDProgMesh"))
{
std::cerr << "Wrong file format.\n";
ifs.close();
return false;
}
clear();
OpenMesh::IO::restore(ifs, n_base_vertices_, swap);
OpenMesh::IO::restore(ifs, n_base_faces_, swap);
OpenMesh::IO::restore(ifs, n_details_, swap);
// update tree_id_bits_
vhierarchy_.set_num_roots(n_base_vertices_);
// read base_mesh
for (i=0; i<n_base_vertices_; ++i)
{
OpenMesh::IO::restore(ifs, p, swap);
OpenMesh::IO::restore(ifs, radius, swap);
OpenMesh::IO::restore(ifs, normal, swap);
OpenMesh::IO::restore(ifs, sin_square, swap);
OpenMesh::IO::restore(ifs, mue_square, swap);
OpenMesh::IO::restore(ifs, sigma_square, swap);
vertex_handle = add_vertex(p);
node_index = vhierarchy_.generate_node_index(i, 1);
node_handle = vhierarchy_.add_node();
index2handle_map[node_index] = node_handle;
// VHierarchyNode &node = vhierarchy_.node(node_handle);
vhierarchy_.node(node_handle).set_index(node_index);
vhierarchy_.node(node_handle).set_vertex_handle(vertex_handle);
vhierarchy_.node(node_handle).set_radius(radius);
vhierarchy_.node(node_handle).set_normal(normal);
vhierarchy_.node(node_handle).set_sin_square(sin_square);
vhierarchy_.node(node_handle).set_mue_square(mue_square);
vhierarchy_.node(node_handle).set_sigma_square(sigma_square);
}
for (i=0; i<n_base_faces_; ++i)
{
OpenMesh::IO::restore(ifs, fvi[0], swap);
OpenMesh::IO::restore(ifs, fvi[1], swap);
OpenMesh::IO::restore(ifs, fvi[2], swap);
add_face(fvi);
}
// read details
for (i=0; i<n_details_; ++i)
{
// position of v0
OpenMesh::IO::restore(ifs, p, swap);
// vsplit info.
OpenMesh::IO::restore(ifs, value, swap);
node_index = VHierarchyNodeIndex(value);
OpenMesh::IO::restore(ifs, value, swap);
fund_lcut_index = VHierarchyNodeIndex(value);
OpenMesh::IO::restore(ifs, value, swap);
fund_rcut_index = VHierarchyNodeIndex(value);
node_handle = index2handle_map[node_index];
vhierarchy_.make_children(node_handle);
vhierarchy_.node(node_handle).set_fund_lcut(fund_lcut_index);
vhierarchy_.node(node_handle).set_fund_rcut(fund_rcut_index);
lchild_handle = vhierarchy_.lchild_handle(node_handle);
rchild_handle = vhierarchy_.rchild_handle(node_handle);
vertex_handle = add_vertex(p);
vhierarchy_.node(lchild_handle).set_vertex_handle(vertex_handle);
vhierarchy_.node(rchild_handle).set_vertex_handle(vhierarchy_.node(node_handle).vertex_handle());
index2handle_map[vhierarchy_.node(lchild_handle).node_index()] = lchild_handle;
index2handle_map[vhierarchy_.node(rchild_handle).node_index()] = rchild_handle;
// view-dependent parameters
OpenMesh::IO::restore(ifs, radius, swap);
OpenMesh::IO::restore(ifs, normal, swap);
OpenMesh::IO::restore(ifs, sin_square, swap);
OpenMesh::IO::restore(ifs, mue_square, swap);
OpenMesh::IO::restore(ifs, sigma_square, swap);
vhierarchy_.node(lchild_handle).set_radius(radius);
vhierarchy_.node(lchild_handle).set_normal(normal);
vhierarchy_.node(lchild_handle).set_sin_square(sin_square);
vhierarchy_.node(lchild_handle).set_mue_square(mue_square);
vhierarchy_.node(lchild_handle).set_sigma_square(sigma_square);
OpenMesh::IO::restore(ifs, radius, swap);
OpenMesh::IO::restore(ifs, normal, swap);
OpenMesh::IO::restore(ifs, sin_square, swap);
OpenMesh::IO::restore(ifs, mue_square, swap);
OpenMesh::IO::restore(ifs, sigma_square, swap);
vhierarchy_.node(rchild_handle).set_radius(radius);
vhierarchy_.node(rchild_handle).set_normal(normal);
vhierarchy_.node(rchild_handle).set_sin_square(sin_square);
vhierarchy_.node(rchild_handle).set_mue_square(mue_square);
vhierarchy_.node(rchild_handle).set_sigma_square(sigma_square);
}
ifs.close();
set_name(_filename);
#ifdef DEBUG_COUT
std::cout << "Opening a VDPM file has finisihed" << std::endl;
#endif
return true;
}
std::ostream& operator << ( std::ostream& _os, const ServerSideVDPM& _o )
{
_os << _o.name();
return _os;
}

View File

@@ -0,0 +1,88 @@
#ifndef OPENMESH_APP_SERVERSIDEVDPM_HH
#define OPENMESH_APP_SERVERSIDEVDPM_HH
#include <OpenMesh/Core/Geometry/VectorT.hh>
#include <OpenMesh/Tools/VDPM/VHierarchy.hh>
#include <vector>
#include <string>
#include <string.h>
using OpenMesh::VDPM::VHierarchy;
using OpenMesh::VDPM::VHierarchyNodeHandleContainer;
class ServerSideVDPM
{
private:
char name_[256];
std::vector<OpenMesh::Vec3f> points_; // points related to this pm
std::vector<OpenMesh::Vec3ui> triangles_; // base mesh triangles
VHierarchy vhierarchy_;
unsigned int n_base_vertices_;
unsigned int n_base_faces_;
unsigned int n_details_;
unsigned char tree_id_bits_;
public:
ServerSideVDPM() { clear(); }
void clear();
const char* name() const { return name_; }
void get_name(char _name[256]) { strcpy(_name, name_); }
void set_name(const char _name[256]) { strcpy(name_, _name); }
std::string
basename(const std::string& _f)
{
std::string::size_type dot = _f.rfind("/");
if (dot == std::string::npos)
return std::string(_f);
return std::string(_f.substr(dot+1, _f.length()-(dot+1)));
}
bool is_same_name(const char _name[256])
{
return (basename( name_ ) == basename( _name ));
}
OpenMesh::VertexHandle add_vertex(const OpenMesh::Vec3f &p);
OpenMesh::FaceHandle add_face(const unsigned int _triangle[3]);
const OpenMesh::Vec3f& point(OpenMesh::VertexHandle _vertex_handle) const
{
return points_[_vertex_handle.idx()];
}
OpenMesh::Vec3f& point(OpenMesh::VertexHandle _vertex_handle)
{
return points_[_vertex_handle.idx()];
}
const VHierarchy& vhierarchy() const { return vhierarchy_; }
VHierarchy& vhierarchy() { return vhierarchy_; }
void vhierarchy_roots(VHierarchyNodeHandleContainer &roots) const;
unsigned int n_base_vertices() const { return n_base_vertices_; }
unsigned int n_base_faces() const { return n_base_faces_; }
unsigned int n_details() const { return n_details_; }
bool open_vd_prog_mesh(const char *_filename);
};
std::ostream& operator << ( std::ostream& _os, const ServerSideVDPM& _o );
typedef std::vector<ServerSideVDPM> ServerSideVDPMContainer;
typedef std::list<ServerSideVDPM> ServerSideVDPMList;
#endif //OPENMESH_APP_SERVERSIDEVDPM_HH defined

View File

@@ -0,0 +1,475 @@
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/VDPMServerSession.hh>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/VDPMServerViewerWidget.hh>
#include <QTextStream>
#include <QByteArray>
using OpenMesh::VDPM::VHierarchyNode;
using OpenMesh::VDPM::Plane3d;
using OpenMesh::VDPM::InvalidVHierarchyNodeHandle;
using OpenMesh::VDPM::debug_print;
bool
VDPMServerSession::
set_vdpm(const char _vdpm_name[256])
{
#ifdef DEBUG_COUT
if (debug_print() == true)
{
std::cout << "Setting vdpm" << std::endl;
}
#endif
vdpm_ = ((VDPMServerViewerWidget *) ((VDPMServerSocket *) parent())->parent())->get_vdpm(_vdpm_name);
if (vdpm_ == NULL)
return false;
vhierarchy_ = &vdpm_->vhierarchy();
VHierarchyNodeHandleContainer roots;
unsigned int n_details;
vdpm_->vhierarchy_roots(roots);
n_details = vdpm_->n_details();
//vfront_.init(roots, n_details);
// vertex hierarchy window
vhwindow_.set_vertex_hierarchy(vdpm_->vhierarchy());
vhwindow_.init(roots);
#ifdef DEBUG_COUT
if (debug_print() == true)
{
std::cout << "setting vdpm ended" << std::endl;
}
#endif
return true;
}
void
VDPMServerSession::
sendBaseMeshToClient()
{
#ifdef DEBUG_COUT
if (debug_print() == true)
{
std::cout << "starting sendBaseMeshToClient()" << std::endl;
}
#endif
#ifdef DEBUG_COUT
if (debug_print() == true)
{
std::cout << "sendBaseMeshToClient() is done" << std::endl;
}
#endif
}
void
VDPMServerSession::
send_vsplit_packets()
{
viewing_parameters_.update_viewing_configurations();
vsplits_.clear();
if (((VDPMServerViewerWidget *) this->parent()->parent())->vd_streaming())
adaptive_refinement();
else
sequential_refinement();
if (debug_print() == true)
{
std::cout << "adaptive refinement is done on the server side" << std::endl;
}
stream_vsplits();
if (debug_print() == true)
{
std::cout << "streameing vsplits is done" << std::endl;
}
if (transmission_complete_ == true)
{
std::cout << "transmission is completed" << std::endl;
}
if (debug_print() == true)
{
std::cout << "send_vsplit_packets() is done" << std::endl;
}
}
void
VDPMServerSession::
readBaseMeshRequestFromClient()
{
int status;
unsigned int string_length;
QDataStream qTcp(socket_);
QString vdpm_name;
// while (waitForMore(10) < sizeof(int));
while ( socket_->bytesAvailable() < sizeof(int) )
socket_->waitForReadyRead(10);
qTcp >> string_length;
// while (waitForMore(10) < (string_length*sizeof(char)));
while (socket_->bytesAvailable() < string_length*sizeof(char) )
socket_->waitForReadyRead(10);
qTcp >> vdpm_name;
if (set_vdpm( vdpm_name.toStdString().c_str() ) != true) status = 0;
else status = 1;
qTcp << status;
socket_->flush();
if (status == 1)
streaming_phase_ = kVSplits;
}
void
VDPMServerSession::
readViewingParametersFromClient()
{
double modelview_matrix[16];
float fovy;
float aspect;
float tolerance_square;
// while (waitForMore(10) < 16*sizeof(double) + 3*sizeof(float));
while ( socket_->bytesAvailable() < 16*sizeof(double) + 3*sizeof(float) )
socket_->waitForReadyRead(10);
QDataStream qTCP(socket_);
qTCP >> modelview_matrix[0]
>> modelview_matrix[1]
>> modelview_matrix[2]
>> modelview_matrix[3]
>> modelview_matrix[4]
>> modelview_matrix[5]
>> modelview_matrix[6]
>> modelview_matrix[7]
>> modelview_matrix[8]
>> modelview_matrix[9]
>> modelview_matrix[10]
>> modelview_matrix[11]
>> modelview_matrix[12]
>> modelview_matrix[13]
>> modelview_matrix[14]
>> modelview_matrix[15]
>> fovy
>> aspect
>> tolerance_square;
viewing_parameters_.set_modelview_matrix(modelview_matrix);
viewing_parameters_.set_fovy(fovy);
viewing_parameters_.set_aspect(aspect);
viewing_parameters_.set_tolerance_square(tolerance_square);
send_vsplit_packets();
fprintf(mem_file, "%d %d %d\n",
memory_requirements_using_window(true),
memory_requirements_using_window(false),
memory_requirements_using_vfront());
}
void
VDPMServerSession::
PrintOutVFront()
{
}
void
VDPMServerSession::
stream_vsplits()
{
// send header (i.e., # of vsplits)
unsigned int i;
VHierarchyNodeHandle node_handle;
OpenMesh::Vec3f pos;
VHierarchyNodeIndex node_index, fund_lcut_index, fund_rcut_index;
float lchild_radius, rchild_radius;
OpenMesh::Vec3f lchild_normal, rchild_normal;
float lchild_sin_square, rchild_sin_square;
float lchild_mue_square, rchild_mue_square;
float lchild_sigma_square, rchild_sigma_square;
unsigned int n_vsplit_packets = (unsigned int) vsplits_.size();
QDataStream qTcp(socket_);
qTcp << n_vsplit_packets;
socket_->flush();
for (i=0; i<n_vsplit_packets; ++i)
{
node_handle = vsplits_[i];
VHierarchyNodeHandle lchild_handle = vhierarchy_->lchild_handle(node_handle);
VHierarchyNodeHandle rchild_handle = vhierarchy_->rchild_handle(node_handle);
VHierarchyNode &node = vhierarchy_->node(node_handle);
VHierarchyNode &lchild = vhierarchy_->node(lchild_handle);
VHierarchyNode &rchild = vhierarchy_->node(rchild_handle);
pos = vdpm_->point(lchild.vertex_handle());
node_index = node.node_index();
fund_lcut_index = node.fund_lcut_index();
fund_rcut_index = node.fund_rcut_index();
lchild_radius = lchild.radius(); rchild_radius = rchild.radius();
lchild_normal = lchild.normal(); rchild_normal = rchild.normal();
lchild_sin_square = lchild.sin_square(); rchild_sin_square = rchild.sin_square();
lchild_mue_square = lchild.mue_square(); rchild_mue_square = rchild.mue_square();
lchild_sigma_square = lchild.sigma_square(); rchild_sigma_square = rchild.sigma_square();
qTcp << pos[0] << pos[1] << pos[2]
<< node_index.value()
<< fund_lcut_index.value()
<< fund_rcut_index.value()
<< lchild_radius
<< lchild_normal[0] << lchild_normal[1] << lchild_normal[2]
<< lchild_sin_square
<< lchild_mue_square
<< lchild_sigma_square
<< rchild_radius
<< rchild_normal[0] << rchild_normal[1] << rchild_normal[2]
<< rchild_sin_square
<< rchild_mue_square
<< rchild_sigma_square;
socket_->flush(); // socket flush
if (debug_print() == true)
{
std::cout << "Write to client " << i << "-th vsplit packets: " << std::endl;
}
}
}
void
VDPMServerSession::
adaptive_refinement()
{
float fovy = viewing_parameters_.fovy();
float tolerance_square = viewing_parameters_.tolerance_square();
float tan_value = tanf(fovy / 2.0f);
kappa_square_ = 4.0f * tan_value * tan_value * tolerance_square;
transmission_complete_ = true;
for (vhwindow_.begin(); vhwindow_.end() != true; vhwindow_.next())
{
VHierarchyNodeHandle node_handle = vhwindow_.node_handle();
if (vhierarchy_->is_leaf_node(node_handle) != true)
{
transmission_complete_ = false;
if (qrefine(node_handle) == true)
{
force_vsplit(node_handle);
}
}
}
}
void
VDPMServerSession::
sequential_refinement()
{
for (vhwindow_.begin(); vhwindow_.end() != true; vhwindow_.next())
{
VHierarchyNodeHandle node_handle = vhwindow_.node_handle();
if (vhierarchy_->is_leaf_node(node_handle) != true)
force_vsplit(node_handle);
if (vsplits_.size() > 10)
break;
}
}
bool
VDPMServerSession::
qrefine(VHierarchyNodeHandle _node_handle)
{
VHierarchyNode &node = vhierarchy_->node(_node_handle);
OpenMesh::Vec3f p = vdpm_->point(node.vertex_handle());
OpenMesh::Vec3f eye_dir = p - viewing_parameters_.eye_pos();
float distance = eye_dir.length();
float distance2 = distance * distance;
float product_value = dot(eye_dir, node.normal());
if (outside_view_frustum(p, node.radius()) == true)
return false;
if (oriented_away(node.sin_square(), distance2, product_value) == true)
return false;
if (screen_space_error(node.mue_square(), node.sigma_square(), distance2, product_value) == true)
return false;
return true;
}
bool
VDPMServerSession::
outside_view_frustum(const OpenMesh::Vec3f &pos, float radius)
{
Plane3d frustum_plane[4];
viewing_parameters_.frustum_planes(frustum_plane);
for (int i = 0; i < 4; i++) {
if (frustum_plane[i].signed_distance(pos) < -radius)
return true;
}
return false;
}
bool
VDPMServerSession::
oriented_away(float sin_square, float distance_square, float product_value)
{
if (product_value > 0 && product_value*product_value > distance_square * sin_square)
return true;
else
return false;
}
bool
VDPMServerSession::
screen_space_error(float mue_square, float sigma_square, float distance_square, float product_value)
{
if ((mue_square >= kappa_square_ * distance_square) ||
(sigma_square * (distance_square - product_value * product_value) >= kappa_square_ * distance_square * distance_square))
return false;
else
return true;
}
void
VDPMServerSession::
force_vsplit(VHierarchyNodeHandle node_handle)
{
VHierarchyNodeHandle lcut_handle, rcut_handle;
VHierarchyNodeIndex fund_lcut_index, fund_rcut_index;
fund_lcut_index = vhierarchy_->fund_lcut_index(node_handle);
fund_rcut_index = vhierarchy_->fund_rcut_index(node_handle);
lcut_handle = active_ancestor_handle(fund_lcut_index);
rcut_handle = active_ancestor_handle(fund_rcut_index);
assert(lcut_handle != InvalidVHierarchyNodeHandle && rcut_handle != InvalidVHierarchyNodeHandle);
while (lcut_handle == rcut_handle)
{
force_vsplit(lcut_handle);
lcut_handle = active_ancestor_handle(fund_lcut_index);
rcut_handle = active_ancestor_handle(fund_rcut_index);
assert(lcut_handle != InvalidVHierarchyNodeHandle && rcut_handle != InvalidVHierarchyNodeHandle);
}
vsplit(node_handle);
}
void
VDPMServerSession::
vsplit(VHierarchyNodeHandle _node_handle)
{
// refine
VHierarchyNodeHandle lchild_handle = vhierarchy_->lchild_handle(_node_handle);
VHierarchyNodeHandle rchild_handle = vhierarchy_->rchild_handle(_node_handle);
vhwindow_.inactivate(_node_handle);
vhwindow_.activate(lchild_handle);
vhwindow_.activate(rchild_handle);
//vfront_.remove(_node_handle);
//vfront_.add(lchild_handle);
//vfront_.add(rchild_handle);
vsplits_.push_back(_node_handle);
}
VHierarchyNodeHandle
VDPMServerSession::
active_ancestor_handle(VHierarchyNodeIndex &node_index)
{
if (node_index.is_valid(vhierarchy_->tree_id_bits()) != true)
return InvalidVHierarchyNodeHandle;
VHierarchyNodeHandle node_handle = vhierarchy_->node_handle(node_index);
while (node_handle != InvalidVHierarchyNodeHandle && vhwindow_.is_active(node_handle) != true)
node_handle = vhierarchy_->parent_handle(node_handle);
return node_handle;
}
unsigned int
VDPMServerSession::
memory_requirements_using_window(bool _estimate)
{
unsigned int mem = 0;
// common
mem += sizeof(VHierarchy*);
mem += sizeof(ViewingParameters);
mem += sizeof(float);
if (_estimate)
{
unsigned int min = vhierarchy_->num_nodes();
unsigned int max = 0;
for (unsigned int i = 0; i < vhierarchy_->num_nodes(); ++i)
{
if (vhwindow_.is_active(VHierarchyNodeHandle((int) i)))
{
min = std::min(min, i);
max = std::max(max, i);
}
}
mem += (max - min) / 8;
}
else
{
mem += vhwindow_.buffer_size();
}
return mem;
}
unsigned int
VDPMServerSession::
memory_requirements_using_vfront()
{
unsigned int mem = 0;
std::list<int> dummy_vfront;
mem += (unsigned int) ceil (vhierarchy_->num_nodes() / 8.0);
mem += sizeof(dummy_vfront);
for (unsigned int i = 0; i < vhierarchy_->num_nodes(); ++i)
{
if (vhwindow_.is_active(VHierarchyNodeHandle((int) i)))
mem += 3*sizeof(int);
}
return mem;
}

View File

@@ -0,0 +1,148 @@
#ifndef OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSERVERSESSION_HH
#define OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSERVERSESSION_HH
#include <QTcpSocket>
#include <QThread>
#include <QDataStream>
#include <QTimer>
#include <iostream>
// #include <QObject>
#include <OpenMesh/Core/Geometry/VectorT.hh>
#include <OpenMesh/Core/Geometry/Plane3d.hh>
#include <OpenMesh/Tools/Utils/Timer.hh>
#include <OpenMesh/Tools/VDPM/StreamingDef.hh>
#include <OpenMesh/Tools/VDPM/VHierarchyNodeIndex.hh>
#include <OpenMesh/Tools/VDPM/ViewingParameters.hh>
#include <OpenMesh/Tools/VDPM/VHierarchy.hh>
#include <OpenMesh/Tools/VDPM/VFront.hh>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/ServerSideVDPM.hh>
#include <OpenMesh/Tools/VDPM/VHierarchyWindow.hh>
using OpenMesh::VDPM::VDPMStreamingPhase;
using OpenMesh::VDPM::kBaseMesh;
using OpenMesh::VDPM::kVSplits;
using OpenMesh::VDPM::VHierarchyWindow;
using OpenMesh::VDPM::VHierarchyNodeIndex;
using OpenMesh::VDPM::VHierarchyNodeHandle;
using OpenMesh::VDPM::ViewingParameters;
using OpenMesh::VDPM::set_debug_print;
class VDPMServerSession : public QThread
{
Q_OBJECT
public:
VDPMServerSession(QTcpSocket* _socket, QObject *parent=0, const char *name=0)
{
socket_ = _socket;
set_debug_print(true);
streaming_phase_ = kBaseMesh;
transmission_complete_ = false;
connect(socket_, SIGNAL(connected()), this, SLOT(socketConnected()));
QTcpSocket::connect(socket_, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));
//connect(this, SIGNAL(connectionClosed()), SLOT(deleteLater()));
QTcpSocket::connect(socket_, SIGNAL(connectionClosed()), this, SLOT(delayedCloseFinished()));
///TODO: find out how to port it from QSocket -> QTcpSocket
// setSocket(sock);
qStatisticsTimer_ = new QTimer(this);
QTcpSocket::connect(qStatisticsTimer_, SIGNAL(timeout()), this, SLOT(print_statistics()));
mem_file = fopen("mem.txt", "w");
start();
}
~VDPMServerSession()
{
fclose(mem_file);
}
// void run()
// {
// exec();
// }
private:
VDPMStreamingPhase streaming_phase_;
bool transmission_complete_;
QTcpSocket* socket_;
private:
void sendBaseMeshToClient();
void send_vsplit_packets();
void readBaseMeshRequestFromClient();
void readViewingParametersFromClient();
void PrintOutVFront();
private slots:
void socketConnected()
{
std::cout << "socket is connected" << std::endl;
}
void socketReadyRead()
{
if (streaming_phase_ == kBaseMesh)
{
readBaseMeshRequestFromClient();
}
else if (streaming_phase_ == kVSplits)
{
readViewingParametersFromClient();
}
}
void print_statistics()
{
//std::cout << memory_requirements(true) << " " << memory_requirements(false) << std::endl;
}
private:
unsigned short tree_id_bits_; // obsolete
ServerSideVDPM* vdpm_;
VHierarchy* vhierarchy_;
VHierarchyWindow vhwindow_;
ViewingParameters viewing_parameters_;
float kappa_square_;
VHierarchyNodeHandleContainer vsplits_;
private:
bool outside_view_frustum(const OpenMesh::Vec3f &pos, float radius);
bool oriented_away(float sin_square, float distance_square, float product_value);
bool screen_space_error(float mue_square, float sigma_square, float distance_square, float product_value);
void adaptive_refinement();
void sequential_refinement();
bool qrefine(VHierarchyNodeHandle _node_handle);
void force_vsplit(VHierarchyNodeHandle node_handle);
void vsplit(VHierarchyNodeHandle _node_handle);
VHierarchyNodeHandle active_ancestor_handle(VHierarchyNodeIndex &node_index);
void stream_vsplits();
public:
bool set_vdpm(const char _vdpm_name[256]);
unsigned int memory_requirements_using_window(bool _estimate);
unsigned int memory_requirements_using_vfront();
// for example
private:
QTimer *qStatisticsTimer_;
FILE *mem_file;
};
#endif //OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSERVERSESSION_HH defined

View File

@@ -0,0 +1,51 @@
#ifndef OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSERVERSOCKET_HH
#define OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSERVERSOCKET_HH
#include <QObject>
#include <QTcpSocket>
#include <QTcpServer>
#include <QVBoxLayout>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/VDPMServerSession.hh>
#include <OpenMesh/Tools/VDPM/StreamingDef.hh>
#include <iostream>
class VDPMServerSocket : public QTcpServer
{
Q_OBJECT
public:
VDPMServerSocket(QObject *parent=0)
: QTcpServer(parent)
{
setMaxPendingConnections(1);
if ( !listen(QHostAddress::Any, VDPM_STREAMING_PORT) )
{
std::cerr << "Failed to bind to port " << VDPM_STREAMING_PORT << std::endl;
exit(1);
}
connect(this, SIGNAL(newConnection()),this,SLOT(newConnections()));
}
public slots:
void newConnections()
{
VDPMServerSession *s = new VDPMServerSession(nextPendingConnection(), this);
//s->set_vdpm();
emit newConnect(s);
std::cout << "new connection"<< /*socket << */std::endl;
}
signals:
void newConnect(VDPMServerSession*);
};
#endif //OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSERVERSOCKET_HH defined

View File

@@ -0,0 +1,81 @@
#include <QKeyEvent>
#include <iterator>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/VDPMServerViewerWidget.hh>
bool
VDPMServerViewerWidget::
open_vd_prog_mesh(const char *_filename)
{
ServerSideVDPMListIter vdpm_it;
vdpm_it = vdpms_.insert(vdpms_.end(), ServerSideVDPM());
ServerSideVDPM &vdpm = *vdpm_it;
return vdpm.open_vd_prog_mesh(_filename);
}
ServerSideVDPM*
VDPMServerViewerWidget::
get_vdpm(const char _vdpm_name[256])
{
ServerSideVDPMListIter vdpm_it;
for (vdpm_it=vdpms_.begin(); vdpm_it!=vdpms_.end(); ++vdpm_it)
{
if (vdpm_it->is_same_name(_vdpm_name) == true)
{
return &(*vdpm_it);
}
}
return NULL;
}
void
VDPMServerViewerWidget::
keyPressEvent(QKeyEvent* _event)
{
bool handled(false);
QString filename;
switch (_event->key())
{
case Qt::Key_D:
set_debug_print(!debug_print());
std::cout << "debug print mode "
<< (debug_print() == true ? "on" : "off") << std::endl;
break;
case Qt::Key_O:
#if defined(OM_CC_MSVC)
filename = QFileDialog::getOpenFileName(0, "", "d:/data/models/spm/", "*.spm");
#else
filename = QFileDialog::getOpenFileName(0, "", "~/data/models/spm/", "*.spm");
#endif
open_vd_prog_mesh( filename.toStdString().c_str() );
break;
case Qt::Key_I:
std::copy( vdpms_.begin(), vdpms_.end(),
std::ostream_iterator<ServerSideVDPM>(std::cout, "\n") );
break;
case Qt::Key_V:
vd_streaming_ = !(vd_streaming_);
if (vd_streaming_)
std::cout << "View-dependent streaming mode" << std::endl;
else
std::cout << "Sequential streaming mode" << std::endl;
break;
case Qt::Key_Q:
case Qt::Key_Escape:
qApp->quit();
}
if (!handled)
_event->ignore();
}

View File

@@ -0,0 +1,72 @@
#ifndef OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSTREAMINGSERVERWIDGET_HH
#define OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSTREAMINGSERVERWIDGET_HH
#include <QApplication>
#include <QWidget>
#include <QFileDialog>
#include <QString>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/ServerSideVDPM.hh>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/VDPMServerSocket.hh>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/VDPMServerSession.hh>
using OpenMesh::VDPM::set_debug_print;
using OpenMesh::VDPM::debug_print;
class VDPMServerViewerWidget : public QWidget
{
Q_OBJECT
public:
//VDPMServerViewerWidget(QWidget *_parent) : QWidget(_parent)
VDPMServerViewerWidget() : QWidget()
{
server = new VDPMServerSocket(this);
// connect(server,
// SIGNAL(newConnection()),
// SLOT(newConnect()));
vd_streaming_ = true;
}
private:
typedef ServerSideVDPMList::iterator ServerSideVDPMListIter;
ServerSideVDPMList vdpms_;
bool vd_streaming_;
VDPMServerSocket *server;
public:
ServerSideVDPM* get_vdpm(const char _vdpm_name[256]);
public:
bool open_vd_prog_mesh(const char *_filename);
bool vd_streaming() const { return vd_streaming_; }
private slots:
void newConnect(VDPMServerSession *s)
{
std::cout << "New connection" << std::endl;
// connect(s, SIGNAL(connectionClosed()), SLOT(connectionClosed()));
}
void connectionClosed()
{
std::cout << "Client closed connection" << std::endl;
}
protected:
virtual void keyPressEvent(QKeyEvent* _event);
};
#endif //OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSTREAMINGSERVERWIDGET_HH defined

View File

@@ -0,0 +1,34 @@
#include <iostream>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/VDPMStreamingServer.hh>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/ServerSideVDPM.hh>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/VDPMServerSocket.hh>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/VDPMServerSession.hh>
#include <OpenMesh/Apps/VDProgMesh/Streaming/Server/VDPMServerViewerWidget.hh>
#include <OpenMesh/Tools/Utils/getopt.h>
#include <QHostAddress>
#include <QApplication>
int main(int argc, char **argv)
{
std::cout << "View-dependent streaming of PM server." << std::endl;
QApplication app(argc, argv);
VDPMServerViewerWidget server_widget;
server_widget.resize(50, 50);
// app.setMainWidget(&server_widget);
server_widget.show();
for (int idx=1; idx < argc; ++idx)
{
std::cout << "loading " << argv[idx] << std::endl;
server_widget.open_vd_prog_mesh( argv[idx] ) ;
}
return app.exec();
}

View File

@@ -0,0 +1,6 @@
#ifndef OPENMESH_APP_VDPMSTREAMINGSERVER_HH
#define OPENMESH_APP_VDPMSTREAMINGSERVER_HH
#endif //OPENMESH_APP_VDPMSTREAMINGSERVER_HH defined

Binary file not shown.