Skip to content

Commit

Permalink
start SendRender3dData, fillrender3ddata, modify on render3drequest. …
Browse files Browse the repository at this point in the history
…nothing finished
  • Loading branch information
ixakalabadie committed Oct 31, 2024
1 parent e85f7c8 commit 53149e9
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 6 deletions.
48 changes: 48 additions & 0 deletions src/Region/RegionHandler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,54 @@ bool RegionHandler::GetRegionHistogramData(
return true;
}

// ***** Fill 3d rendering *****
// GeneratorProgressCallback progress_callback, CARTA::Render3DData& render3d_data


bool RegionHandler::SendRender3DData(int file_id, int region_id, int viewer_id,
AxisRange& spectral_range, int rebin_xy, int rebin_z, std::shared_ptr<Frame>& frame, CARTA::Render3DResponse& render3d_response) {

RegionState region_state = _regions.at(region_id)->GetRegionState();

auto stokes = frame->CurrentStokes();
PreviewCubeParameters cube_parameters(file_id, region_id, spectral_range, rebin_xy, rebin_z, stokes, region_state);

auto frame_id = GetRender3DViewerFrameId(viewer_id);
bool viewer_frame_set = _frames.find(frame_id) != _frames.end();

// Update cube settings for existing ID.
// Set unique locks so in-progress cubes are completed before update.
std::unique_lock render3d_cube_lock(_render3d_cube_mutex);
if (_render3d_cubes.find(viewer_id) == _render3d_cubes.end() ||
!_render3d_cubes.at(viewer_id)->HasSameParameters(cube_parameters)) {
// Cube changed, see if set for another viewer ID
bool cube_found(false);
for (auto& render3d_cube : _render3d_cubes) {
if (render3d_cube.second->HasSameParameters(cube_parameters)) {
_render3d_cubes[viewer_id] = render3d_cube.second;
cube_found = true;
break;
}
}
if (!cube_found) {
_render3d_cubes[viewer_id] = std::shared_ptr<PvPreviewCube>(new PvPreviewCube(cube_parameters));
}

// If preview cube changed, then frame for its preview image cube is invalid
viewer_frame_set = false;
}
auto render3d_cube = _render3d_cubes.at(viewer_id);
bool render3d_cube_loaded = render3d_cube->CubeLoaded();
render3d_cube_lock.unlock();


}

bool RegionHandler::FillRender3DData(std::function<void(CARTA::Render3DData render3d_data)> cb) {


}

// ***** Fill spectral profile *****

bool RegionHandler::FillSpectralProfileData(
Expand Down
1 change: 1 addition & 0 deletions src/Region/RegionHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class RegionHandler {
bool FillRegionStatsData(std::function<void(CARTA::RegionStatsData stats_data)> cb, int region_id, int file_id);
bool FillPointSpatialProfileData(int file_id, int region_id, std::vector<CARTA::SpatialProfileData>& spatial_data_vec);
bool FillLineSpatialProfileData(int file_id, int region_id, std::function<void(CARTA::SpatialProfileData profile_data)> cb);
bool FillRender3DData();

// Calculate moments
bool CalculateMoments(int file_id, int region_id, const std::shared_ptr<Frame>& frame, GeneratorProgressCallback progress_callback,
Expand Down
79 changes: 73 additions & 6 deletions src/Session/Session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1338,12 +1338,63 @@ bool Session::OnConcatStokesFiles(const CARTA::ConcatStokesFiles& message, uint3
}

void Session::OnRender3DRequest(const CARTA::Render3DRequest& render3d_request, uint32_t request_id) {
// return true if data sent
bool data_sent(false);

// Unpack request message
int file_id(render3d_request.file_id());
int region_id(render3d_request.region_id());
int viewer_id(render3d_request.viewer_id());
bool keep(render3d_request.keep());
AxisRange spectral_range;
if (render3d_request.has_spectral_range()) {
spectral_range = AxisRange(render3d_request.spectral_range().min(), render3d_request.spectral_range().max());
} else {
spectral_range = AxisRange(0, frame->Depth() - 1);
}
int rebin_xy = std::max(render3d_request.rebin_xy(), 1);
int rebin_z = std::max(render3d_request.rebin_z(), 1);
auto compression = render3d_request.compression_type();
float image_quality = render3d_request.image_compression_quality();

CARTA::Render3DResponse render3d_response;
std::cout << "Render3D function called" << std::endl;

// Checks for valid request:
// 1. Region is set. For Render3D Region is optional
// if (!RegionSet(region_id, true)) {
// render3d_response.set_message("3D Rendering requested for invalid region.");
// return false;
// }
bool is_image_region(region_id == IMAGE_REGION_ID);
if (!is_image_region) {
if (!RegionSet(region_id)) {
render3d_response.set_message("3D rendering cube requested for invalid region id.");
return false;
}
if (!IsClosedRegion(region_id)) {
render3d_response.set_message("3D rendering cube requested for invalid region type.");
return false;
}

// 2. Region is closed
if (!IsClosedRegion(region_id)) {
render3d_response.set_message("Region type not supported for 3D Rendering.");
return false;
}

// 3. Image has spectral axis
if (!frame->CoordinateSystem()->hasSpectralAxis()) {
render3d_response.set_message("No spectral coordinate for generating 3D rendering.");
return false;
}

// 4. Image is smaller than limit
if (frame->Width() * frame->Height() * frame->Depth() > MAX_RENDER3D_PIXELS) {
render3d_response.set_message("Cube size exceeds maximum for 3D Rendering. Please use smaller region or spectral range.");
return false;
}

if (_frames.count(file_id)) {
// condition statement to check if the a region is selected. cursor_region is 0 and NONE, IMAGE and ACTIVE are < 0
// if (!_region_handler || (region_id <= CURSOR_REGION_ID)) {
Expand All @@ -1354,16 +1405,32 @@ void Session::OnRender3DRequest(const CARTA::Render3DRequest& render3d_request,
auto& frame = _frames.at(file_id);
CARTA::Render3DData render3d_data;

data_sent = _region_handler->SendRender3DData(
[&](CARTA::Render3DData& render3d_data) {
// send (partial) render3d datacube to frontend
SendEvent(CARTA::EventType::RENDER3D_DATA, request_id, render3d_data);
},
)

// Set render3d progress callback function
auto progress_callback = [&](float progress) {
auto render3d_progress = Message::Render3DProgress(file_id, region_id, progress, viewer_id);
SendEvent(CARTA::EventType::RENDER3D_PROGRESS, request_id, render3d_progress);
};
// auto progress_callback = [&](float progress) {
// auto render3d_progress = Message::Render3DProgress(file_id, region_id, progress, viewer_id);
// SendEvent(CARTA::EventType::RENDER3D_PROGRESS, request_id, render3d_progress);
// };

if (_region_handler->CalculateRender3DData(render3d_request, frame, progress_callback, render3d_response, render3d_data)) {
// if (_region_handler->CalculateRender3DData(render3d_request, frame, progress_callback, render3d_response, render3d_data)) {

}
// }

}
// check if data was sent and send response accordingly
if (data_sent) {
render3d_response.set_success(true);
} else {
render3d_response.set_success(false);
render3d_response.set_message("3D data not sent.");
}
SendEvent(CARTA::EventType::RENDER3D_RESPONSE, request_id, render3d_response);
}

void Session::OnPvRequest(const CARTA::PvRequest& pv_request, uint32_t request_id) {
Expand Down

0 comments on commit 53149e9

Please sign in to comment.