📄 vdpmclientviewerwidget.cc
字号:
void
VDPMClientViewerWidget::
update_viewing_parameters()
{
viewing_parameters_.set_fovy(fovy());
viewing_parameters_.set_aspect((float) width() / (float) height());
viewing_parameters_.set_modelview_matrix(modelview_matrix());
viewing_parameters_.update_viewing_configurations();
}
/////////////////////////////////////////////////
// streaming related functions
/////////////////////////////////////////////////
bool
VDPMClientViewerWidget::
request_base_mesh()
{
if (streaming_phase_ != kBaseMesh)
return false;
if (qFilename_.isEmpty() == true)
{
std::cout << "Please, specify the base mesh filename." << std::endl;
return false;
}
QDataStream qTcp(qSocket_);
qTcp << qFilename_.length();
qTcp << qFilename_;
qSocket_->flush();
return true;
}
bool
VDPMClientViewerWidget::
receive_base_mesh()
{
int status;
QDataStream qTcp(qSocket_);
while (qSocket_->waitForMore(10) < sizeof(int));
qTcp >> status;
if (status == 0)
{
std::cout << "There is no such a VDPM files in the server side." << std::endl;
return false;
}
streaming_phase_ = kVSplitHeader;
std::cout << "A view-dependent streaming is ready." << std::endl;
return true;
}
void
VDPMClientViewerWidget::
send_viewing_information()
{
session_timer_.start();
QDataStream qTCP(qSocket_);
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]
<< viewing_parameters_.fovy()
<< viewing_parameters_.aspect()
<< viewing_parameters_.tolerance_square();
qSocket_->flush();
session_timer_.stop();
fprintf(session_file, "%d %d\n", frame_, (int) session_timer_.mseconds());
global_timer_.stop();
fprintf(uplink_file, "%d %zd\n", (int) global_timer_.mseconds(), 16*sizeof(double) + 3*sizeof(float));
global_timer_.cont();
}
void
VDPMClientViewerWidget::
receive_vsplit_header()
{
if (qSocket_->bytesAvailable() < sizeof(unsigned int))
return;
QDataStream qTcp(qSocket_);
// while (qSocket_->waitForMore(10) < sizeof(unsigned int));
qTcp >> n_vsplit_packets_;
if (n_vsplit_packets_ > 0)
{
streaming_phase_ = kVSplits;
if (debug_print() == true)
{
std::cout << "Server will transmit " << n_vsplit_packets_
<< " of vsplit packets to me" << std::endl;
}
receive_vsplit_packets();
}
else
{
session_running_ = false;
}
}
void
VDPMClientViewerWidget::
receive_vsplit_packets()
{
static unsigned int n_vsplits = 0;
static unsigned int len = (int) (17 * sizeof(float) + 3 * sizeof(int));
if (qSocket_->bytesAvailable() < len)
return;
QString str;
OpenMesh::Vec3f pos;
VHierarchyNodeIndex node_index, fund_lcut_index, fund_rcut_index;
float radius[2];
OpenMesh::Vec3f normal[2];
float sin_square[2];
float mue_square[2];
float sigma_square[2];
unsigned int value[3];
global_timer_.stop();
fprintf(downlink_file, "%d %d\n", (int) global_timer_.mseconds(), (int) qSocket_->bytesAvailable());
global_timer_.cont();
session_timer_.start();
while ( qSocket_->bytesAvailable() >= len )
{
if (vd_streaming_) transmitted_datasize_ += (int) len;
//if (vd_streaming_) transmitted_datasize_ += (int) 3*sizeof(int) + 3*sizeof(float); // only for non-refinement cliet
else transmitted_datasize_ += (int) 3*sizeof(int) + 3*sizeof(float);
if (max_transmitted_datasize_ > 0)
{
if (transmitted_datasize_ > max_transmitted_datasize_)
{
if (vd_streaming_) transmitted_datasize_ -= (int) len;
//if (vd_streaming_) transmitted_datasize_ -= (int) 3*sizeof(int) + 3*sizeof(float); // only for non-refinement cliet
else transmitted_datasize_ -= (int) 3*sizeof(int) + 3*sizeof(float);
return;
}
}
QDataStream qTcp(qSocket_);
qTcp >> pos[0] >> pos[1] >> pos[2]
>> value[0]
>> value[1]
>> value[2]
>> radius[0]
>> (normal[0])[0] >> (normal[0])[1] >> (normal[0])[2]
>> sin_square[0]
>> mue_square[0] >> sigma_square[0]
>> radius[1]
>> (normal[1])[0] >> (normal[1])[1] >> (normal[1])[2]
>> sin_square[1]
>> mue_square[1] >> sigma_square[1];
node_index = VHierarchyNodeIndex(value[0]);
fund_lcut_index = VHierarchyNodeIndex(value[1]);
fund_rcut_index = VHierarchyNodeIndex(value[2]);
update_vhierarchy(pos,
node_index, fund_lcut_index, fund_rcut_index,
radius, normal, sin_square, mue_square, sigma_square);
std::cout << "transmitted datasize: " << transmitted_datasize_ << std::endl;
if (debug_print() == true)
{
std::cout << "Pkg #" << n_vsplits << std::endl;
}
++n_vsplits;
if (n_vsplits >= n_vsplit_packets_)
{
n_vsplits = 0;
streaming_phase_ = kVSplitHeader;
session_running_ = false;
if (debug_print() == true)
{
std::cout << "transmission of vsplit packets is complete" << std::endl;
}
break;
}
}
session_timer_.stop();
fprintf(session_file, "%d %d\n", frame_, (int) session_timer_.mseconds());
updateGL();
if (n_vsplits != n_vsplit_packets_)
qSessionTimer_->start(300, true);
}
void
VDPMClientViewerWidget::
update_vhierarchy(
const OpenMesh::Vec3f &_pos, // 3D position of v0
const VHierarchyNodeIndex &_node_index, // vhierarchy index of v1
const VHierarchyNodeIndex &_fund_lcut_index, // vhierarchy index of fundamental lcut
const VHierarchyNodeIndex &_fund_rcut_index, // vhierarchy index of fundamental rcut
const float _radius[2], // radius of lchild & rchild
const OpenMesh::Vec3f _normal[2], // normal of lchild & rchild
const float _sin_square[2], // sin_square of lchild & rchild
const float _mue_square[2], // mue_square of lchild & rchild
const float _sigma_square[2] // sigma_square of lchild & rchild
)
{
OpenMesh::VertexHandle vertex_handle;
VHierarchyNodeHandle node_handle, lchild_handle, rchild_handle;
node_handle = vhierarchy_.node_handle(_node_index);
vhierarchy_.make_children(node_handle);
lchild_handle = vhierarchy_.lchild_handle(node_handle);
rchild_handle = vhierarchy_.rchild_handle(node_handle);
vhierarchy_.node(node_handle).set_fund_lcut(_fund_lcut_index);
vhierarchy_.node(node_handle).set_fund_rcut(_fund_rcut_index);
vertex_handle = mesh_.add_vertex(_pos);
vhierarchy_.node(lchild_handle).set_vertex_handle(vertex_handle);
vhierarchy_.node(rchild_handle).set_vertex_handle(vhierarchy_.node(node_handle).vertex_handle());
vhierarchy_.node(lchild_handle).set_radius(_radius[0]);
vhierarchy_.node(lchild_handle).set_normal(_normal[0]);
vhierarchy_.node(lchild_handle).set_sin_square(_sin_square[0]);
vhierarchy_.node(lchild_handle).set_mue_square(_mue_square[0]);
vhierarchy_.node(lchild_handle).set_sigma_square(_sigma_square[0]);
vhierarchy_.node(rchild_handle).set_radius(_radius[1]);
vhierarchy_.node(rchild_handle).set_normal(_normal[1]);
vhierarchy_.node(rchild_handle).set_sin_square(_sin_square[1]);
vhierarchy_.node(rchild_handle).set_mue_square(_mue_square[1]);
vhierarchy_.node(rchild_handle).set_sigma_square(_sigma_square[1]);
#ifdef EXAMPLE_CREATION
__add_children(_node_index);
#endif
}
/////////////////////////////////////////////////
// example related functions
/////////////////////////////////////////////////
void VDPMClientViewerWidget::save_views()
{
FILE *camera_file = fopen("camera.cmr", "w");
GLdouble current_modelview_matrix[16], current_projection_matrix[16];
memcpy(current_modelview_matrix, modelview_matrix(), 16*sizeof(GLdouble));
memcpy(current_projection_matrix, projection_matrix(), 16*sizeof(GLdouble));
fprintf(camera_file, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
current_modelview_matrix[0], current_modelview_matrix[1], current_modelview_matrix[2], current_modelview_matrix[3],
current_modelview_matrix[4], current_modelview_matrix[5], current_modelview_matrix[6], current_modelview_matrix[7],
current_modelview_matrix[8], current_modelview_matrix[9], current_modelview_matrix[10], current_modelview_matrix[11],
current_modelview_matrix[12], current_modelview_matrix[13], current_modelview_matrix[14], current_modelview_matrix[15]);
fprintf(camera_file, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
current_projection_matrix[0], current_projection_matrix[1], current_projection_matrix[2], current_projection_matrix[3],
current_projection_matrix[4], current_projection_matrix[5], current_projection_matrix[6], current_projection_matrix[7],
current_projection_matrix[8], current_projection_matrix[9], current_projection_matrix[10], current_projection_matrix[11],
current_projection_matrix[12], current_projection_matrix[13], current_projection_matrix[14], current_projection_matrix[15]);
fprintf(camera_file, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
reserved_modelview_matrix_[0], reserved_modelview_matrix_[1], reserved_modelview_matrix_[2], reserved_modelview_matrix_[3],
reserved_modelview_matrix_[4], reserved_modelview_matrix_[5], reserved_modelview_matrix_[6], reserved_modelview_matrix_[7],
reserved_modelview_matrix_[8], reserved_modelview_matrix_[9], reserved_modelview_matrix_[10], reserved_modelview_matrix_[11],
reserved_modelview_matrix_[12], reserved_modelview_matrix_[13], reserved_modelview_matrix_[14], reserved_modelview_matrix_[15]);
fprintf(camera_file, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
reserved_projection_matrix_[0], reserved_projection_matrix_[1], reserved_projection_matrix_[2], reserved_projection_matrix_[3],
reserved_projection_matrix_[4], reserved_projection_matrix_[5], reserved_projection_matrix_[6], reserved_projection_matrix_[7],
reserved_projection_matrix_[8], reserved_projection_matrix_[9], reserved_projection_matrix_[10], reserved_projection_matrix_[11],
reserved_projection_matrix_[12], reserved_projection_matrix_[13], reserved_projection_matrix_[14], reserved_projection_matrix_[15]);
fclose(camera_file);
}
void VDPMClientViewerWidget::load_views(const char *camera_filename)
{
FILE *camera_file = fopen(camera_filename, "r");
GLdouble current_modelview_matrix[16], current_projection_matrix[16];
fscanf(camera_file, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
&(current_modelview_matrix[0]), &(current_modelview_matrix[1]), &(current_modelview_matrix[2]), &(current_modelview_matrix[3]),
&(current_modelview_matrix[4]), &(current_modelview_matrix[5]), &(current_modelview_matrix[6]), &(current_modelview_matrix[7]),
&(current_modelview_matrix[8]), &(current_modelview_matrix[9]), &(current_modelview_matrix[10]), &(current_modelview_matrix[11]),
&(current_modelview_matrix[12]), &(current_modelview_matrix[13]), &(current_modelview_matrix[14]), &(current_modelview_matrix[15]));
fscanf(camera_file, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
&(current_projection_matrix[0]), &(current_projection_matrix[1]), &(current_projection_matrix[2]), &(current_projection_matrix[3]),
&(current_projection_matrix[4]), &(current_projection_matrix[5]), &(current_projection_matrix[6]), &(current_projection_matrix[7]),
&(current_projection_matrix[8]), &(current_projection_matrix[9]), &(current_projection_matrix[10]), &(current_projection_matrix[11]),
&(current_projection_matrix[12]), &(current_projection_matrix[13]), &(current_projection_matrix[14]), &(current_projection_matrix[15]));
fscanf(camera_file, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
&(reserved_modelview_matrix_[0]), &(reserved_modelview_matrix_[1]), &(reserved_modelview_matrix_[2]), &(reserved_modelview_matrix_[3]),
&(reserved_modelview_matrix_[4]), &(reserved_modelview_matrix_[5]), &(reserved_modelview_matrix_[6]), &(reserved_modelview_matrix_[7]),
&(reserved_modelview_matrix_[8]), &(reserved_modelview_matrix_[9]), &(reserved_modelview_matrix_[10]), &(reserved_modelview_matrix_[11]),
&(reserved_modelview_matrix_[12]), &(reserved_modelview_matrix_[13]), &(reserved_modelview_matrix_[14]), &(reserved_modelview_matrix_[15]));
fscanf(camera_file, "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf\n",
&(reserved_projection_matrix_[0]), &(reserved_projection_matrix_[1]), &(reserved_projection_matrix_[2]), &(reserved_projection_matrix_[3]),
&(reserved_projection_matrix_[4]), &(reserved_projection_matrix_[5]), &(reserved_projection_matrix_[6]), &(reserved_projection_matrix_[7]),
&(reserved_projection_matrix_[8]), &(reserved_projection_matrix_[9]), &(reserved_projection_matrix_[10]), &(reserved_projection_matrix_[11]),
&(reserved_projection_matrix_[12]), &(reserved_projection_matrix_[13]), &(reserved_projection_matrix_[14]), &(reserved_projection_matrix_[15]));
fclose(camera_file);
set_modelview_matrix(current_modelview_matrix);
set_projection_matrix(current_projection_matrix);
adaptive_mode_ = false;
}
void VDPMClientViewerWidget::print_statistics()
{
const float angle = 360.0/(float)n_viewpoints_;
Vec3f axis = Vec3f(0,1,0);
Vec3f delta = Vec3f(0, 0.7f*(bbMin_[1] - bbMax_[1])/n_viewpoints_, 0);
rotate(axis, -angle);
set_scene_pos(center() + delta, 1.0f * radius() );
updateGL();
if (++nth_viewpoint_ < n_viewpoints_)
qAnimationTimer_->start(500, true);
}
void VDPMClientViewerWidget::look_around()
{
const float angle = 360.0/(float)n_viewpoints_;
Vec3f axis = Vec3f(0,1,0);
Vec3f delta = Vec3f(0, 0.7f*(bbMin_[1] - bbMax_[1])/n_viewpoints_, 0);
rotate(axis, -angle);
set_scene_pos(center() + delta, 1.0f * radius() );
updateGL();
save_screen(true);
if (++nth_viewpoint_ < n_viewpoints_)
qAnimationTimer_->start(3000, true);
}
void VDPMClientViewerWidget::save_screen(bool _flag)
{
setCursor( waitCursor );
if (_flag == true) // shot from the reserved view-point
{
GLdouble current_modelview_matrix[16];
GLdouble current_projection_matrix[16];
bool current_adaptive_mode = adaptive_mode_;
memcpy(current_modelview_matrix, modelview_matrix(), 16*sizeof(GLdouble));
memcpy(current_projection_matrix, projection_matrix(), 16*sizeof(GLdouble));
set_modelview_matrix(reserved_modelview_matrix_);
set_projection_matrix(reserved_projection_matrix_);
adaptive_mode_ = false;
updateGL();
// shot from the reserved view-point
char rfilename[256];
sprintf(rfilename, "rview%03d.bmp", nth_viewpoint_);
screen_capture(rfilename);
std::cout << "shot from the reserved view-point" << std::endl;
set_modelview_matrix(current_modelview_matrix);
set_projection_matrix(current_projection_matrix);
adaptive_mode_ = current_adaptive_mode;
}
updateGL();
// shot from the current view-point
char cfilename[256];
sprintf(cfilename, "cview%03d.bmp", nth_viewpoint_);
screen_capture(cfilename);
std::cout << "shot from the current view-point" << std::endl;
setCursor( pointingHandCursor );
}
void VDPMClientViewerWidget::screen_capture(const char *_filename)
{
// CImageData image(width(), height());
// glReadBuffer(GL_BACK);
// glReadPixels(0, 0, width(), height(), GL_RGB, GL_UNSIGNED_BYTE, (GLvoid*) image.rgbMap());
// image.SaveBMP(_filename, width(), height());
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -