00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
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
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
00152 }
00153
00154 private:
00155 unsigned short tree_id_bits_;
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
00182 private:
00183 QTimer *qStatisticsTimer_;
00184 FILE *mem_file;
00185 };
00186
00187 #endif //OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSERVERSESSION_HH defined