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 <QTcpSocket>
00046 #include <QThread>
00047 #include <QDataStream>
00048 #include <QTimer>
00049 #include <iostream>
00050
00051 #include <OpenMesh/Core/Geometry/VectorT.hh>
00052 #include <OpenMesh/Core/Geometry/Plane3d.hh>
00053 #include <OpenMesh/Tools/Utils/Timer.hh>
00054 #include <OpenMesh/Tools/VDPM/StreamingDef.hh>
00055 #include <OpenMesh/Tools/VDPM/VHierarchyNodeIndex.hh>
00056 #include <OpenMesh/Tools/VDPM/ViewingParameters.hh>
00057 #include <OpenMesh/Tools/VDPM/VHierarchy.hh>
00058 #include <OpenMesh/Tools/VDPM/VFront.hh>
00059 #include <OpenMesh/Apps/VDProgMesh/Streaming/Server/ServerSideVDPM.hh>
00060 #include <OpenMesh/Tools/VDPM/VHierarchyWindow.hh>
00061
00062
00063 using OpenMesh::VDPM::VDPMStreamingPhase;
00064 using OpenMesh::VDPM::kBaseMesh;
00065 using OpenMesh::VDPM::kVSplits;
00066
00067 using OpenMesh::VDPM::VHierarchyWindow;
00068 using OpenMesh::VDPM::VHierarchyNodeIndex;
00069 using OpenMesh::VDPM::VHierarchyNodeHandle;
00070 using OpenMesh::VDPM::ViewingParameters;
00071
00072 using OpenMesh::VDPM::set_debug_print;
00073
00074 class VDPMServerSession : public QThread
00075 {
00076
00077 Q_OBJECT
00078
00079 public:
00080
00081 VDPMServerSession(QTcpSocket* _socket, QObject *parent=0, const char *name=0)
00082 {
00083 socket_ = _socket;
00084
00085 set_debug_print(true);
00086
00087 streaming_phase_ = kBaseMesh;
00088 transmission_complete_ = false;
00089
00090 connect(socket_, SIGNAL(connected()), this, SLOT(socketConnected()));
00091 QTcpSocket::connect(socket_, SIGNAL(readyRead()), this, SLOT(socketReadyRead()));
00092
00093 QTcpSocket::connect(socket_, SIGNAL(connectionClosed()), this, SLOT(delayedCloseFinished()));
00094
00096
00097
00098 qStatisticsTimer_ = new QTimer(this);
00099 QTcpSocket::connect(qStatisticsTimer_, SIGNAL(timeout()), this, SLOT(print_statistics()));
00100
00101 mem_file = fopen("mem.txt", "w");
00102
00103 start();
00104 }
00105
00106 ~VDPMServerSession()
00107 {
00108 fclose(mem_file);
00109 }
00110
00111
00112
00113
00114
00115
00116 private:
00117
00118 VDPMStreamingPhase streaming_phase_;
00119 bool transmission_complete_;
00120
00121 QTcpSocket* socket_;
00122
00123 private:
00124
00125 void sendBaseMeshToClient();
00126 void send_vsplit_packets();
00127 void readBaseMeshRequestFromClient();
00128 void readViewingParametersFromClient();
00129
00130 void PrintOutVFront();
00131
00132 private slots:
00133
00134 void socketConnected()
00135 {
00136 std::cout << "socket is connected" << std::endl;
00137 }
00138
00139 void socketReadyRead()
00140 {
00141 if (streaming_phase_ == kBaseMesh)
00142 {
00143 readBaseMeshRequestFromClient();
00144 }
00145 else if (streaming_phase_ == kVSplits)
00146 {
00147 readViewingParametersFromClient();
00148 }
00149 }
00150
00151 void print_statistics()
00152 {
00153
00154 }
00155
00156 private:
00157 unsigned short tree_id_bits_;
00158 ServerSideVDPM* vdpm_;
00159 VHierarchy* vhierarchy_;
00160 VHierarchyWindow vhwindow_;
00161 ViewingParameters viewing_parameters_;
00162 float kappa_square_;
00163 VHierarchyNodeHandleContainer vsplits_;
00164
00165 private:
00166 bool outside_view_frustum(const OpenMesh::Vec3f &pos, float radius);
00167 bool oriented_away(float sin_square, float distance_square, float product_value);
00168 bool screen_space_error(float mue_square, float sigma_square, float distance_square, float product_value);
00169
00170 void adaptive_refinement();
00171 void sequential_refinement();
00172 bool qrefine(VHierarchyNodeHandle _node_handle);
00173 void force_vsplit(VHierarchyNodeHandle node_handle);
00174 void vsplit(VHierarchyNodeHandle _node_handle);
00175 VHierarchyNodeHandle active_ancestor_handle(VHierarchyNodeIndex &node_index);
00176 void stream_vsplits();
00177
00178 public:
00179 bool set_vdpm(const char _vdpm_name[256]);
00180 unsigned int memory_requirements_using_window(bool _estimate);
00181 unsigned int memory_requirements_using_vfront();
00182
00183
00184 private:
00185 QTimer *qStatisticsTimer_;
00186 FILE *mem_file;
00187 };
00188
00189 #endif //OPENMESH_APP_VDPMSTREAMING_SERVER_VDPMSERVERSESSION_HH defined