예제 #1
0
void Visualizer::CaptureRenderOption(const std::string &filename/* = ""*/)
{
    std::string json_filename = filename;
    if (json_filename.empty()) {
        std::string timestamp = GetCurrentTimeStamp();
        json_filename = "RenderOption_" + timestamp + ".json";
    }
    PrintDebug("[Visualizer] Render option capture to %s\n",
            json_filename.c_str());
    WriteIJsonConvertible(json_filename, *render_option_ptr_);
}
예제 #2
0
/*----------------------------------------------------------------------
|   NPT_System::SleepUntil
+---------------------------------------------------------------------*/
NPT_Result
NPT_System::SleepUntil(const NPT_TimeStamp& when)
{
    NPT_TimeStamp now;
    GetCurrentTimeStamp(now);
    if (when > now) {
        NPT_TimeInterval duration = when-now;
        return Sleep(duration);
    } else {
        return NPT_SUCCESS;
    }
}
예제 #3
0
/*----------------------------------------------------------------------
|   NPT_System::GetRandomInteger
+---------------------------------------------------------------------*/
NPT_UInt32 
NPT_System::GetRandomInteger()
{
    static bool seeded = false;
    if (seeded == false) {
        NPT_TimeStamp now;
        GetCurrentTimeStamp(now);
        SetRandomSeed((NPT_UInt32)now.ToNanos());
        seeded = true;
    }

    return rand();
}
예제 #4
0
/*
	==========================================================================
	Description:
		Prepare Measurement request action frame and enqueue it into
		management queue waiting for transmition.

	Parametrs:
		1. the destination mac address of the frame.

	Return	: None.
	==========================================================================
 */
VOID EnqueueMeasurementReq(
	IN PRTMP_ADAPTER pAd,
	IN PUCHAR pDA,
	IN UINT8 MeasureToken,
	IN UINT8 MeasureReqMode,
	IN UINT8 MeasureReqType,
	IN UINT8 MeasureCh,
	IN UINT16 MeasureDuration)
{
	PUCHAR pOutBuffer = NULL;
	NDIS_STATUS NStatus;
	ULONG FrameLen;
	HEADER_802_11 ActHdr;
	MEASURE_REQ_INFO MeasureReqIE;
	UINT8 RmReqDailogToken = RandomByte(pAd);
	UINT64 MeasureStartTime = GetCurrentTimeStamp(pAd);

	// build action frame header.
	MgtMacHeaderInit(pAd, &ActHdr, SUBTYPE_ACTION, 0, pDA,
						pAd->CurrentAddress);

	NStatus = MlmeAllocateMemory(pAd, (PVOID)&pOutBuffer);  //Get an unused nonpaged memory
	if(NStatus != NDIS_STATUS_SUCCESS)
	{
		DBGPRINT(RT_DEBUG_TRACE, ("%s() allocate memory failed \n", __func__));
		return;
	}
	NdisMoveMemory(pOutBuffer, (PCHAR)&ActHdr, sizeof(HEADER_802_11));
	FrameLen = sizeof(HEADER_802_11);

	InsertActField(pAd, (pOutBuffer + FrameLen), &FrameLen, CATEGORY_SPECTRUM, SPEC_MRQ);

	// fill Dialog Token
	InsertDialogToken(pAd, (pOutBuffer + FrameLen), &FrameLen, MeasureToken);

	// prepare Measurement IE.
	NdisZeroMemory(&MeasureReqIE, sizeof(MEASURE_REQ_INFO));
	MeasureReqIE.Token = RmReqDailogToken;
	MeasureReqIE.ReqMode.word = MeasureReqMode;
	MeasureReqIE.ReqType = MeasureReqType;
	MeasureReqIE.MeasureReq.ChNum = MeasureCh;
	MeasureReqIE.MeasureReq.MeasureStartTime = cpu2le64(MeasureStartTime);
	MeasureReqIE.MeasureReq.MeasureDuration = cpu2le16(MeasureDuration);
	InsertMeasureReqIE(pAd, (pOutBuffer + FrameLen), &FrameLen, &MeasureReqIE);

	MiniportMMRequest(pAd, QID_AC_BE, pOutBuffer, FrameLen);
	MlmeFreeMemory(pAd, pOutBuffer);

	return;
}
예제 #5
0
void Visualizer::CaptureScreenImage(const std::string &filename/* = ""*/,
        bool do_render/* = true*/)
{
    std::string png_filename = filename;
    std::string camera_filename;
    if (png_filename.empty()) {
        std::string timestamp = GetCurrentTimeStamp();
        png_filename = "ScreenCapture_" + timestamp + ".png";
        camera_filename = "ScreenCamera_" + timestamp + ".json";
    }
    Image screen_image;
    screen_image.PrepareImage(view_control_ptr_->GetWindowWidth(),
            view_control_ptr_->GetWindowHeight(), 3, 1);
    if (do_render) {
        Render();
        is_redraw_required_ = false;
    }
    glFinish();
    glReadPixels(0, 0, view_control_ptr_->GetWindowWidth(),
            view_control_ptr_->GetWindowHeight(), GL_RGB, GL_UNSIGNED_BYTE,
            screen_image.data_.data());

    // glReadPixels get the screen in a vertically flipped manner
    // Thus we should flip it back.
    Image png_image;
    png_image.PrepareImage(view_control_ptr_->GetWindowWidth(),
            view_control_ptr_->GetWindowHeight(), 3, 1);
    int bytes_per_line = screen_image.BytesPerLine();
    for (int i = 0; i < screen_image.height_; i++) {
        memcpy(png_image.data_.data() + bytes_per_line * i,
                screen_image.data_.data() + bytes_per_line *
                (screen_image.height_ - i - 1), bytes_per_line);
    }

    PrintDebug("[Visualizer] Screen capture to %s\n", png_filename.c_str());
    WriteImage(png_filename, png_image);
    if (!camera_filename.empty()) {
        PrintDebug("[Visualizer] Screen camera capture to %s\n",
                camera_filename.c_str());
        PinholeCameraTrajectory trajectory;
        trajectory.extrinsic_.resize(1);
        view_control_ptr_->ConvertToPinholeCameraParameters(
                trajectory.intrinsic_, trajectory.extrinsic_[0]);
        WriteIJsonConvertible(camera_filename, trajectory);
    }
}
예제 #6
0
void Visualizer::CaptureDepthPointCloud(const std::string &filename/* = ""*/,
        bool do_render/* = true*/, bool convert_to_world_coordinate/* = false*/)
{
    std::string ply_filename = filename;
    std::string camera_filename;
    if (ply_filename.empty()) {
        std::string timestamp = GetCurrentTimeStamp();
        ply_filename = "DepthCapture_" + timestamp + ".ply";
        camera_filename = "DepthCamera_" + timestamp + ".json";
    }
    Image depth_image;
    depth_image.PrepareImage(view_control_ptr_->GetWindowWidth(),
            view_control_ptr_->GetWindowHeight(), 1, 4);

    if (do_render) {
        Render();
        is_redraw_required_ = false;
    }
    glFinish();

#if __APPLE__
    // On OSX with Retina display and glfw3, there is a bug with glReadPixels().
    // When using glReadPixels() to read a block of depth data. The data is
    // horizontally stretched (vertically it is fine). This issue is related
    // to GLFW_SAMPLES hint. When it is set to 0 (anti-aliasing disabled),
    // glReadPixels() works fine. See this post for details:
    // http://stackoverflow.com/questions/30608121/glreadpixel-one-pass-vs-looping-through-points
    // The reason of this bug is unknown. The current workaround is to read
    // depth buffer column by column. This is 15~30 times slower than one block
    // reading glReadPixels().
    std::vector<float> float_buffer(depth_image.height_);
    float *p = (float *)depth_image.data_.data();
    for (int j = 0; j < depth_image.width_; j++) {
        glReadPixels(j, 0, 1, depth_image.width_,
                GL_DEPTH_COMPONENT, GL_FLOAT,
                float_buffer.data());
        for (int i = 0; i < depth_image.height_; i++) {
            p[i * depth_image.width_ + j] = float_buffer[i];
        }
    }
#else //__APPLE__
    // By default, glReadPixels read a block of depth buffer.
    glReadPixels(0, 0, depth_image.width_, depth_image.height_,
            GL_DEPTH_COMPONENT, GL_FLOAT, depth_image.data_.data());
#endif //__APPLE__

    GLHelper::GLMatrix4f mvp_matrix;
    if (convert_to_world_coordinate) {
        mvp_matrix = view_control_ptr_->GetMVPMatrix();
    }
    else {
        mvp_matrix = view_control_ptr_->GetProjectionMatrix();
    }

    // glReadPixels get the screen in a vertically flipped manner
    // We should flip it back, and convert it to the correct depth value
    PointCloud depth_pointcloud;
    for (int i = 0; i < depth_image.height_; i++) {
        float *p_depth = (float *)(depth_image.data_.data() +
                depth_image.BytesPerLine() * i);
        for (int j = 0; j < depth_image.width_; j++) {
            if (p_depth[j] == 1.0) {
                continue;
            }
            depth_pointcloud.points_.push_back(GLHelper::Unproject(
                    Eigen::Vector3d(j + 0.5, i + 0.5, p_depth[j]),
                    mvp_matrix,
                    view_control_ptr_->GetWindowWidth(),
                    view_control_ptr_->GetWindowHeight()));
        }
    }

    PrintDebug("[Visualizer] Depth point cloud capture to %s\n",
            ply_filename.c_str());
    WritePointCloud(ply_filename, depth_pointcloud);
    if (!camera_filename.empty()) {
        PrintDebug("[Visualizer] Depth camera capture to %s\n",
                camera_filename.c_str());
        PinholeCameraTrajectory trajectory;
        trajectory.extrinsic_.resize(1);
        view_control_ptr_->ConvertToPinholeCameraParameters(
                trajectory.intrinsic_, trajectory.extrinsic_[0]);
        WriteIJsonConvertible(camera_filename, trajectory);
    }
}
예제 #7
0
void Visualizer::CaptureDepthImage(const std::string &filename/* = ""*/,
        bool do_render/* = true*/, double depth_scale/* = 1000.0*/)
{
    std::string png_filename = filename;
    std::string camera_filename;
    if (png_filename.empty()) {
        std::string timestamp = GetCurrentTimeStamp();
        png_filename = "DepthCapture_" + timestamp + ".png";
        camera_filename = "DepthCamera_" + timestamp + ".json";
    }
    Image depth_image;
    depth_image.PrepareImage(view_control_ptr_->GetWindowWidth(),
            view_control_ptr_->GetWindowHeight(), 1, 4);

    if (do_render) {
        Render();
        is_redraw_required_ = false;
    }
    glFinish();

#if __APPLE__
    // On OSX with Retina display and glfw3, there is a bug with glReadPixels().
    // When using glReadPixels() to read a block of depth data. The data is
    // horizontally streched (vertically it is fine). This issue is related
    // to GLFW_SAMPLES hint. When it is set to 0 (anti-aliasing disabled),
    // glReadPixels() works fine. See this post for details:
    // http://stackoverflow.com/questions/30608121/glreadpixel-one-pass-vs-looping-through-points
    // The reason of this bug is unknown. The current workaround is to read
    // depth buffer column by column. This is 15~30 times slower than one block
    // reading glReadPixels().
    std::vector<float> float_buffer(depth_image.height_);
    float *p = (float *)depth_image.data_.data();
    for (int j = 0; j < depth_image.width_; j++) {
        glReadPixels(j, 0, 1, depth_image.width_,
                GL_DEPTH_COMPONENT, GL_FLOAT,
                float_buffer.data());
        for (int i = 0; i < depth_image.height_; i++) {
            p[i * depth_image.width_ + j] = float_buffer[i];
        }
    }
#else //__APPLE__
    // By default, glReadPixels read a block of depth buffer.
    glReadPixels(0, 0, depth_image.width_, depth_image.height_,
            GL_DEPTH_COMPONENT, GL_FLOAT, depth_image.data_.data());
#endif //__APPLE__

    // glReadPixels get the screen in a vertically flipped manner
    // We should flip it back, and convert it to the correct depth value
    Image png_image;
    double z_near = view_control_ptr_->GetZNear();
    double z_far = view_control_ptr_->GetZFar();

    png_image.PrepareImage(view_control_ptr_->GetWindowWidth(),
            view_control_ptr_->GetWindowHeight(), 1, 2);
    for (int i = 0; i < depth_image.height_; i++) {
        float *p_depth = (float *)(depth_image.data_.data() +
                depth_image.BytesPerLine() * (depth_image.height_ - i - 1));
        uint16_t *p_png = (uint16_t *)(png_image.data_.data() +
                png_image.BytesPerLine() * i);
        for (int j = 0; j < depth_image.width_; j++) {
            if (p_depth[j] == 1.0) {
                continue;
            }
            double z_depth = 2.0 * z_near * z_far /
                    (z_far + z_near - (2.0 * (double)p_depth[j] - 1.0) *
                    (z_far - z_near));
            p_png[j] = (uint16_t)std::min(std::round(depth_scale * z_depth),
                    (double)INT16_MAX);
        }
    }

    PrintDebug("[Visualizer] Depth capture to %s\n", png_filename.c_str());
    WriteImage(png_filename, png_image);
    if (!camera_filename.empty()) {
        PrintDebug("[Visualizer] Depth camera capture to %s\n",
                camera_filename.c_str());
        PinholeCameraTrajectory trajectory;
        trajectory.extrinsic_.resize(1);
        view_control_ptr_->ConvertToPinholeCameraParameters(
                trajectory.intrinsic_, trajectory.extrinsic_[0]);
        WriteIJsonConvertible(camera_filename, trajectory);
    }
}