Skip to content

Commit

Permalink
ENH: Socket control drr visibility toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
NicerNewerCar committed Jan 5, 2024
1 parent 6444737 commit 34ef0bb
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 0 deletions.
16 changes: 16 additions & 0 deletions autoscoper/src/net/Socket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,22 @@ void Socket::handleMessage(QTcpSocket * connection, char* data, qint64 length)
}
break;

case 17:
// Set the visablity of a volume
{
size_t offset = preamble_offset;

SocketReadValuePointerMacro(volumeID, qint32);
SocketReadValuePointerMacro(visible, qint32);

std::cerr << "Setting volume " << (int)*volumeID << " to have a visablity: " << (int)*visible << std::endl;

m_mainwindow->setVolumeVisibility(*volumeID, (bool)*visible);

connection->write(QByteArray(1, 17));
}
break;

default:
std::cerr << "Cannot handle message" << std::endl;
connection->write(QByteArray(1,0));
Expand Down
4 changes: 4 additions & 0 deletions autoscoper/src/ui/AutoscoperMainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2503,3 +2503,7 @@ int AutoscoperMainWindow::getNumVolumes() {
int AutoscoperMainWindow::getNumFrames() {
return tracker->trial()->num_frames;
}

void AutoscoperMainWindow::setVolumeVisibility(int volume, bool visible) {
volumes_widget->setVolumeVisibility(volume, visible);
}
1 change: 1 addition & 0 deletions autoscoper/src/ui/AutoscoperMainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class AutoscoperMainWindow : public QMainWindow{
void optimizeFrame(int volumeID, int frame, int dframe, int repeats, int opt_method, unsigned int max_iter, double min_limit, double max_limit, int cf_model, unsigned int stall_iter);
int getNumVolumes();
int getNumFrames();
void setVolumeVisibility(int volumeID, bool visible);


// Backup Save
Expand Down
5 changes: 5 additions & 0 deletions autoscoper/src/ui/VolumeDockWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ void VolumeDockWidget::addVolume(const std::string& filename, int idx){

}

void VolumeDockWidget::setVolumeVisibility(unsigned int volume_index, bool visible) {
VolumeListWidgetItem* item = dynamic_cast<VolumeListWidgetItem*>(dock->listWidget->item(volume_index));
item->on_visiblilityCheckBox__toggled(visible);
}

void VolumeDockWidget::on_listWidget_currentItemChanged (QListWidgetItem* current, QListWidgetItem* previous) {
if (current != NULL)
{
Expand Down
1 change: 1 addition & 0 deletions autoscoper/src/ui/VolumeDockWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class VolumeDockWidget : public QDockWidget{

void clearVol();
void addVolume(const std::string& filename, int idx);
void setVolumeVisibility(unsigned int volume_index, bool visible);


QString getVolumeName(int volume_index);
Expand Down
11 changes: 11 additions & 0 deletions scripts/matlab/AutoscoperConnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,17 @@ function saveFullDRR(obj)
data = fread(obj.socket_descriptor, obj.socket_descriptor.BytesAvailable);
end

function setVolumeVisibility(obj, volNum, visible)
if nargin < 3
error('Not enough input arguments');
end
fwrite(obj.socket_descriptor, [...
17...
typecast(int32(volNum), 'uint8') ...
typecast(int32(visible), 'uint8') ...
]);
end

function trackingDialog(obj, volNum, startframe, endframe, repeats, max_itr, min_lim, max_lim, max_stall_itr, dframe, opt_method, cf_model, opt_init_heuristic)
% Performs optimization on a range of frames
% Only obj, volNum, startframe, and endframe are required
Expand Down
12 changes: 12 additions & 0 deletions scripts/python/PyAutoscoper/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,3 +594,15 @@ def getNumFrames(self) -> int:
response = self._send_command(0x0F) # 15
num_frames = struct.unpack("i", response[1:])[0]
return num_frames

def setVolumeVisibility(self, volume: int, visible: bool) -> None:
"""
Sets the visibility of the given volume
:param volume: The ID of the volume.
:param visible: If True makes the volume visible. If False make the volume invisible.
:raises AutoscoperServerError: If the server fails to get the number of frames
:raises AutoscoperConnectionError: If the connection to the server is lost
"""
self._send_command(0x11, volume, int(visible)) # 17

0 comments on commit 34ef0bb

Please sign in to comment.