OpenMesh
|
00001 /*===========================================================================*\ 00002 * * 00003 * OpenMesh * 00004 * Copyright (C) 2001-2011 by Computer Graphics Group, RWTH Aachen * 00005 * www.openmesh.org * 00006 * * 00007 *---------------------------------------------------------------------------* 00008 * This file is part of OpenMesh. * 00009 * * 00010 * OpenMesh is free software: you can redistribute it and/or modify * 00011 * it under the terms of the GNU Lesser General Public License as * 00012 * published by the Free Software Foundation, either version 3 of * 00013 * the License, or (at your option) any later version with the * 00014 * following exceptions: * 00015 * * 00016 * If other files instantiate templates or use macros * 00017 * or inline functions from this file, or you compile this file and * 00018 * link it with other files to produce an executable, this file does * 00019 * not by itself cause the resulting executable to be covered by the * 00020 * GNU Lesser General Public License. This exception does not however * 00021 * invalidate any other reasons why the executable file might be * 00022 * covered by the GNU Lesser General Public License. * 00023 * * 00024 * OpenMesh is distributed in the hope that it will be useful, * 00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00027 * GNU Lesser General Public License for more details. * 00028 * * 00029 * You should have received a copy of the GNU LesserGeneral Public * 00030 * License along with OpenMesh. If not, * 00031 * see <http://www.gnu.org/licenses/>. * 00032 * * 00033 \*===========================================================================*/ 00034 00035 /*===========================================================================*\ 00036 * * 00037 * $Revision: 362 $ * 00038 * $Date: 2011-01-26 10:21:12 +0100 (Mi, 26 Jan 2011) $ * 00039 * * 00040 \*===========================================================================*/ 00041 00042 #ifndef OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSERVERSESSION_HH 00043 #define OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSERVERSESSION_HH 00044 00045 #include <qsocket.h> 00046 #include <qthread.h> 00047 #include <qdatastream.h> 00048 #include <qtimer.h> 00049 #include <iostream> 00050 #include <OpenMesh/Core/Geometry/VectorT.hh> 00051 #include <OpenMesh/Core/Geometry/Plane3d.hh> 00052 #include <OpenMesh/Tools/Utils/Timer.hh> 00053 #include <OpenMesh/Tools/VDPM/StreamingDef.hh> 00054 #include <OpenMesh/Tools/VDPM/VHierarchyNodeIndex.hh> 00055 #include <OpenMesh/Tools/VDPM/ViewingParameters.hh> 00056 #include <OpenMesh/Tools/VDPM/VHierarchy.hh> 00057 #include <OpenMesh/Tools/VDPM/VFront.hh> 00058 #include <OpenMesh/Apps/VDProgMesh/Streaming/Server/ServerSideVDPM.hh> 00059 #include <OpenMesh/Tools/VDPM/VHierarchyWindow.hh> 00060 00061 00062 using OpenMesh::VDPM::VDPMStreamingPhase; 00063 using OpenMesh::VDPM::kBaseMesh; 00064 using OpenMesh::VDPM::kVSplits; 00065 00066 using OpenMesh::VDPM::VHierarchyWindow; 00067 using OpenMesh::VDPM::VHierarchyNodeIndex; 00068 using OpenMesh::VDPM::VHierarchyNodeHandle; 00069 using OpenMesh::VDPM::ViewingParameters; 00070 00071 using OpenMesh::VDPM::set_debug_print; 00072 00073 class VDPMServerSession : public QSocket, public QThread 00074 { 00075 00076 Q_OBJECT 00077 00078 public: 00079 00080 VDPMServerSession(int sock, QObject *parent=0, const char *name=0) 00081 : QSocket(parent, name) 00082 { 00083 set_debug_print(true); 00084 00085 streaming_phase_ = kBaseMesh; 00086 transmission_complete_ = false; 00087 00088 connect(this, SIGNAL(connected()), SLOT(socketConnected())); 00089 connect(this, SIGNAL(readyRead()), SLOT(socketReadyRead())); 00090 //connect(this, SIGNAL(connectionClosed()), SLOT(deleteLater())); 00091 connect(this, SIGNAL(connectionClosed()), SLOT(delayedCloseFinished())); 00092 setSocket(sock); 00093 00094 00095 qStatisticsTimer_ = new QTimer(this); 00096 connect(qStatisticsTimer_, SIGNAL(timeout()), this, SLOT(print_statistics())); 00097 00098 mem_file = fopen("mem.txt", "w"); 00099 00100 start(); 00101 } 00102 00103 ~VDPMServerSession() 00104 { 00105 fclose(mem_file); 00106 } 00107 00108 void run() 00109 { 00110 while (true) 00111 { 00112 sleep(1); 00113 } 00114 } 00115 00116 private: 00117 00118 VDPMStreamingPhase streaming_phase_; 00119 bool transmission_complete_; 00120 00121 private: 00122 00123 void sendBaseMeshToClient(); 00124 void send_vsplit_packets(); 00125 void readBaseMeshRequestFromClient(); 00126 void readViewingParametersFromClient(); 00127 00128 void PrintOutVFront(); 00129 00130 private slots: 00131 00132 void socketConnected() 00133 { 00134 std::cout << "socket is connected" << std::endl; 00135 } 00136 00137 void socketReadyRead() 00138 { 00139 if (streaming_phase_ == kBaseMesh) 00140 { 00141 readBaseMeshRequestFromClient(); 00142 } 00143 else if (streaming_phase_ == kVSplits) 00144 { 00145 readViewingParametersFromClient(); 00146 } 00147 } 00148 00149 void print_statistics() 00150 { 00151 //std::cout << memory_requirements(true) << " " << memory_requirements(false) << std::endl; 00152 } 00153 00154 private: 00155 unsigned short tree_id_bits_; // obsolete 00156 ServerSideVDPM* vdpm_; 00157 VHierarchy* vhierarchy_; 00158 VHierarchyWindow vhwindow_; 00159 ViewingParameters viewing_parameters_; 00160 float kappa_square_; 00161 VHierarchyNodeHandleContainer vsplits_; 00162 00163 private: 00164 bool outside_view_frustum(const OpenMesh::Vec3f &pos, float radius); 00165 bool oriented_away(float sin_square, float distance_square, float product_value); 00166 bool screen_space_error(float mue_square, float sigma_square, float distance_square, float product_value); 00167 00168 void adaptive_refinement(); 00169 void sequential_refinement(); 00170 bool qrefine(VHierarchyNodeHandle _node_handle); 00171 void force_vsplit(VHierarchyNodeHandle node_handle); 00172 void vsplit(VHierarchyNodeHandle _node_handle); 00173 VHierarchyNodeHandle active_ancestor_handle(VHierarchyNodeIndex &node_index); 00174 void stream_vsplits(); 00175 00176 public: 00177 bool set_vdpm(const char _vdpm_name[256]); 00178 unsigned int memory_requirements_using_window(bool _estimate); 00179 unsigned int memory_requirements_using_vfront(); 00180 00181 // for example 00182 private: 00183 QTimer *qStatisticsTimer_; 00184 FILE *mem_file; 00185 }; 00186 00187 #endif //OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSERVERSESSION_HH defined