Skip to content

Commit

Permalink
STYLE: Correct indentation Re #1
Browse files Browse the repository at this point in the history
  • Loading branch information
monicagsevilla committed Jan 18, 2022
1 parent 929cabe commit d2b842d
Show file tree
Hide file tree
Showing 3 changed files with 687 additions and 689 deletions.
290 changes: 145 additions & 145 deletions Collaboration/Logic/vtkSlicerCollaborationLogic.cxx
Expand Up @@ -4,7 +4,7 @@
See COPYRIGHT.txt
or http://www.slicer.org/copyright/copyright.txt for details.
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down Expand Up @@ -73,7 +73,7 @@ void vtkSlicerCollaborationLogic::PrintSelf(ostream& os, vtkIndent indent)
}

//---------------------------------------------------------------------------
void vtkSlicerCollaborationLogic::SetMRMLSceneInternal(vtkMRMLScene * newScene)
void vtkSlicerCollaborationLogic::SetMRMLSceneInternal(vtkMRMLScene* newScene)
{
vtkNew<vtkIntArray> events;
events->InsertNextValue(vtkMRMLScene::NodeAddedEvent);
Expand All @@ -94,11 +94,11 @@ void vtkSlicerCollaborationLogic::RegisterNodes()
}
if (!scene->IsNodeClassRegistered("vtkMRMLCollaborationNode"))
{
scene->RegisterNodeClass(vtkSmartPointer<vtkMRMLCollaborationNode>::New());
scene->RegisterNodeClass(vtkSmartPointer<vtkMRMLCollaborationNode>::New());
}
if (!scene->IsNodeClassRegistered("vtkMRMLCollaborationConnectorNode"))
{
scene->RegisterNodeClass(vtkSmartPointer<vtkMRMLCollaborationConnectorNode>::New());
scene->RegisterNodeClass(vtkSmartPointer<vtkMRMLCollaborationConnectorNode>::New());
}
}

Expand All @@ -112,135 +112,135 @@ void vtkSlicerCollaborationLogic::UpdateFromMRMLScene()
void vtkSlicerCollaborationLogic
::OnMRMLSceneNodeAdded(vtkMRMLNode* node)
{
if (!node || !this->GetMRMLScene())
{
vtkErrorMacro("OnMRMLSceneNodeAdded: Invalid MRML scene or input node!");
return;
if (!node || !this->GetMRMLScene())
{
vtkErrorMacro("OnMRMLSceneNodeAdded: Invalid MRML scene or input node!");
return;
}
if (node->IsA("vtkMRMLCollaborationNode"))
{
// Check if a ConnectorNode for the new CollaborationNode exists
vtkMRMLCollaborationNode* collaborationNode = vtkMRMLCollaborationNode::SafeDownCast(node);
const char* collabconnectorNodeID = collaborationNode->GetCollaborationConnectorNodeID();

if (!collabconnectorNodeID) {
// Create a ConnectorNode
vtkMRMLCollaborationConnectorNode* connectorNode =
vtkMRMLCollaborationConnectorNode::SafeDownCast(this->GetMRMLScene()->CreateNodeByClass("vtkMRMLCollaborationConnectorNode"));
this->GetMRMLScene()->AddNode(connectorNode);
// Set the same name as the Collaboration Node + Connector
char* collaborationNodeName = node->GetName();
char connectorName[] = "Connector";
char* connectorNodeName = new char[std::strlen(collaborationNodeName) + std::strlen(connectorName) + 1];
std::strcpy(connectorNodeName, collaborationNodeName);
std::strcat(connectorNodeName, connectorName);
connectorNode->SetName(connectorNodeName);
const char* connectorNodeID = connectorNode->GetID();
//collaborationNode->connectorNodeID = connectorNodeID;
collaborationNode->SetCollaborationConnectorNodeID(connectorNodeID);
connectorNode->SetType(0);
}
if (node->IsA("vtkMRMLCollaborationNode"))
this->Modified();
}
else if (node->IsA("vtkMRMLModelNode") || node->IsA("vtkMRMLLinearTransformNode") ||
node->IsA("vtkMRMLMarkupsNode") || node->IsA("vtkMRMLTextNode") || node->IsA("vtkMRMLScalarVolumeNode"))
{
// fiducials do not include the description of "Received by OpenIGTLink"
if (node->IsA("vtkMRMLMarkupsFiducialNode") && this->collaborationNodeSelected)
{
// Check if a ConnectorNode for the new CollaborationNode exists
vtkMRMLCollaborationNode* collaborationNode = vtkMRMLCollaborationNode::SafeDownCast(node);
const char* collabconnectorNodeID = collaborationNode->GetCollaborationConnectorNodeID();

if (!collabconnectorNodeID) {
// Create a ConnectorNode
vtkMRMLCollaborationConnectorNode* connectorNode =
vtkMRMLCollaborationConnectorNode::SafeDownCast(this->GetMRMLScene()->CreateNodeByClass("vtkMRMLCollaborationConnectorNode"));
this->GetMRMLScene()->AddNode(connectorNode);
// Set the same name as the Collaboration Node + Connector
char* collaborationNodeName = node->GetName();
char connectorName[] = "Connector";
char* connectorNodeName = new char[std::strlen(collaborationNodeName) + std::strlen(connectorName) + 1];
std::strcpy(connectorNodeName, collaborationNodeName);
std::strcat(connectorNodeName, connectorName);
connectorNode->SetName(connectorNodeName);
const char* connectorNodeID = connectorNode->GetID();
//collaborationNode->connectorNodeID = connectorNodeID;
collaborationNode->SetCollaborationConnectorNodeID(connectorNodeID);
connectorNode->SetType(0);
}
this->Modified();
const char* connectorNodeID = this->collaborationNodeSelected->GetCollaborationConnectorNodeID();
vtkMRMLCollaborationConnectorNode* connectorNode =
vtkMRMLCollaborationConnectorNode::SafeDownCast(this->GetMRMLScene()->GetNodeByID(connectorNodeID));
int state = connectorNode->GetState();
// if connection is active, we are assuming it was received through OpenIGTLink
if (state == 2)
{
node->SetDescription("Received by OpenIGTLink");
}
}
else if (node->IsA("vtkMRMLModelNode") || node->IsA("vtkMRMLLinearTransformNode") ||
node->IsA("vtkMRMLMarkupsNode") || node->IsA("vtkMRMLTextNode") || node->IsA("vtkMRMLScalarVolumeNode"))
{
// fiducials do not include the description of "Received by OpenIGTLink"
if (node->IsA("vtkMRMLMarkupsFiducialNode") && this->collaborationNodeSelected)
// check if it was received through an OpenIGTLink connection
const char* nodeDescription = node->GetDescription();
if (nodeDescription) {
if (strcmp(nodeDescription, "Received by OpenIGTLink") == 0)
{
// set attribute of the collaboration node to the added node
node->SetAttribute(this->collaborationNodeSelected->GetID(), "true");
// add node reference to the collaboration node
if (this->collaborationNodeSelected)
{
const char* connectorNodeID = this->collaborationNodeSelected->GetCollaborationConnectorNodeID();
vtkMRMLCollaborationConnectorNode* connectorNode =
vtkMRMLCollaborationConnectorNode::SafeDownCast(this->GetMRMLScene()->GetNodeByID(connectorNodeID));
int state = connectorNode->GetState();
// if connection is active, we are assuming it was received through OpenIGTLink
if (state == 2)
{
node->SetDescription("Received by OpenIGTLink");
}
this->collaborationNodeSelected->AddCollaborationSynchronizedNodeID(node->GetID());

}
// check if it was received through an OpenIGTLink connection
const char* nodeDescription = node->GetDescription();
if (nodeDescription) {
if (strcmp(nodeDescription, "Received by OpenIGTLink") == 0)
// update transforms
// get transformed nodes
vtkStringArray* collection = this->collaborationNodeSelected->GetCollaborationSynchronizedNodeIDs();
std::string transformedNodesText = "";
for (int i = 0; i < collection->GetNumberOfTuples(); i++)
{
std::string ID = collection->GetValue(i);
vtkMRMLNode* node = vtkMRMLNode::SafeDownCast(this->GetMRMLScene()->GetNodeByID(ID));
if (node->IsA("vtkMRMLLinearTransformNode"))
{
const char* textNodeReferenceID = node->GetNthNodeReferenceID("TextNode", 0);
vtkMRMLTextNode* transformTextNode =
vtkMRMLTextNode::SafeDownCast(this->GetMRMLScene()->GetNodeByID(textNodeReferenceID));
if (transformTextNode)
{
// set attribute of the collaboration node to the added node
node->SetAttribute(this->collaborationNodeSelected->GetID(), "true");
// add node reference to the collaboration node
if (this->collaborationNodeSelected)
{
this->collaborationNodeSelected->AddCollaborationSynchronizedNodeID(node->GetID());

}
// update transforms
// get transformed nodes
vtkStringArray* collection = this->collaborationNodeSelected->GetCollaborationSynchronizedNodeIDs();
std::string transformedNodesText = "";
for (int i = 0; i < collection->GetNumberOfTuples(); i++)
{
std::string ID = collection->GetValue(i);
vtkMRMLNode* node = vtkMRMLNode::SafeDownCast(this->GetMRMLScene()->GetNodeByID(ID));
if (node->IsA("vtkMRMLLinearTransformNode"))
{
const char* textNodeReferenceID = node->GetNthNodeReferenceID("TextNode", 0);
vtkMRMLTextNode* transformTextNode =
vtkMRMLTextNode::SafeDownCast(this->GetMRMLScene()->GetNodeByID(textNodeReferenceID));
if (transformTextNode)
{
std::stringstream ss;
ss << transformTextNode->GetText();
vtkXMLDataElement* res =
vtkXMLUtilities::ReadElementFromStream(ss);
this->orderTransforms(res);
}
}
}
std::stringstream ss;
ss << transformTextNode->GetText();
vtkXMLDataElement* res =
vtkXMLUtilities::ReadElementFromStream(ss);
this->orderTransforms(res);
}
}
}
}
}
}
}

void vtkSlicerCollaborationLogic::orderTransforms(vtkXMLDataElement* res)
{
// read attributes
int numberOfAttributes = res->GetNumberOfAttributes();
std::vector<const char*> atts_v;
for (int attributeIndex = 0; attributeIndex < numberOfAttributes; attributeIndex++)
{
const char* attName = res->GetAttributeName(attributeIndex);
const char* attValue = res->GetAttribute(attName);
atts_v.push_back(attName);
atts_v.push_back(attValue);
}
atts_v.push_back(nullptr);
const char** atts = (atts_v.data());
// read attributes
int numberOfAttributes = res->GetNumberOfAttributes();
std::vector<const char*> atts_v;
for (int attributeIndex = 0; attributeIndex < numberOfAttributes; attributeIndex++)
{
const char* attName = res->GetAttributeName(attributeIndex);
const char* attValue = res->GetAttribute(attName);
atts_v.push_back(attName);
atts_v.push_back(attValue);
}
atts_v.push_back(nullptr);
const char** atts = (atts_v.data());

// get transform node
std::string transformName = res->GetAttribute("TransformName");
vtkMRMLLinearTransformNode* transformNode =
vtkMRMLLinearTransformNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(transformName.c_str()));
// get transform node
std::string transformName = res->GetAttribute("TransformName");
vtkMRMLLinearTransformNode* transformNode =
vtkMRMLLinearTransformNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(transformName.c_str()));

// get transformed nodes attribute
std::string transformedNodesStr = res->GetAttribute("TransformedNodes");
// get transformed nodes attribute
std::string transformedNodesStr = res->GetAttribute("TransformedNodes");

// get every coordinate
std::stringstream ss(transformedNodesStr);
std::vector<std::string> vect;
while (ss.good())
{
std::string substr;
getline(ss, substr, ',');
vect.push_back(substr);
}
int numberOfTransformedNodes = vect.size();
for (int i = 0; i < numberOfTransformedNodes; i++)
// get every coordinate
std::stringstream ss(transformedNodesStr);
std::vector<std::string> vect;
while (ss.good())
{
std::string substr;
getline(ss, substr, ',');
vect.push_back(substr);
}
int numberOfTransformedNodes = vect.size();
for (int i = 0; i < numberOfTransformedNodes; i++)
{
vtkMRMLTransformableNode* node =
vtkMRMLTransformableNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(vect[i].c_str()));
if (node)
{
vtkMRMLTransformableNode* node =
vtkMRMLTransformableNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName(vect[i].c_str()));
if (node)
{
node->SetAndObserveTransformNodeID(transformNode->GetID());
}
node->SetAndObserveTransformNodeID(transformNode->GetID());
}
}
}


Expand All @@ -258,8 +258,8 @@ ::OnMRMLSceneNodeRemoved(vtkMRMLNode* node)
vtkMRMLCollaborationNode* collaborationNode = vtkMRMLCollaborationNode::SafeDownCast(node);
// Get the connector node associated to the collaboration node
const char* connectorNodeID = collaborationNode->GetCollaborationConnectorNodeID();
vtkMRMLCollaborationConnectorNode* connectorNode =
vtkMRMLCollaborationConnectorNode::SafeDownCast(this->GetMRMLScene()->GetNodeByID(connectorNodeID));
vtkMRMLCollaborationConnectorNode* connectorNode =
vtkMRMLCollaborationConnectorNode::SafeDownCast(this->GetMRMLScene()->GetNodeByID(connectorNodeID));
this->GetMRMLScene()->RemoveNode(connectorNode);
collaborationNode->SetCollaborationConnectorNodeID(nullptr);
this->Modified();
Expand All @@ -268,33 +268,33 @@ ::OnMRMLSceneNodeRemoved(vtkMRMLNode* node)

void vtkSlicerCollaborationLogic::loadAvatars()
{
// get directory
std::string moduleShareDirectory = this->GetModuleShareDirectory();

// Create a models logic for convenient loading of components
vtkSlicerModelsLogic* modelsLogic = vtkSlicerModelsLogic::New();
modelsLogic->SetMRMLScene(this->GetMRMLScene());

// Load basic additional device models

// Head
std::string headModelFilePath = moduleShareDirectory + "/" + AVATAR_HEAD_MODEL_NAME + ".stl";
vtkMRMLModelNode* headModelNode = modelsLogic->AddModel(headModelFilePath.c_str());
// Left hand
std::string handPointLModelFilePath = moduleShareDirectory + "/" + AVATAR_HANDPOINTL_MODEL_NAME + ".stl";
vtkMRMLModelNode* handPointLModelNode = modelsLogic->AddModel(handPointLModelFilePath.c_str());

// Right hand
std::string handPointRModelFilePath = moduleShareDirectory + "/" + AVATAR_HANDPOINTR_MODEL_NAME + ".stl";
vtkMRMLModelNode* handPointRModelNode = modelsLogic->AddModel(handPointRModelFilePath.c_str());

// Apply transforms
vtkMRMLLinearTransformNode* transformHeadNode = vtkMRMLLinearTransformNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName("VirtualReality.HMD"));
headModelNode->SetAndObserveTransformNodeID(transformHeadNode->GetID());
vtkMRMLLinearTransformNode* transformHandLNode = vtkMRMLLinearTransformNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName("VirtualReality.LeftController"));
handPointLModelNode->SetAndObserveTransformNodeID(transformHandLNode->GetID());
vtkMRMLLinearTransformNode* transformHandRNode = vtkMRMLLinearTransformNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName("VirtualReality.RightController"));
handPointRModelNode->SetAndObserveTransformNodeID(transformHandRNode->GetID());
// get directory
std::string moduleShareDirectory = this->GetModuleShareDirectory();

// Create a models logic for convenient loading of components
vtkSlicerModelsLogic* modelsLogic = vtkSlicerModelsLogic::New();
modelsLogic->SetMRMLScene(this->GetMRMLScene());

// Load basic additional device models

// Head
std::string headModelFilePath = moduleShareDirectory + "/" + AVATAR_HEAD_MODEL_NAME + ".stl";
vtkMRMLModelNode* headModelNode = modelsLogic->AddModel(headModelFilePath.c_str());

// Left hand
std::string handPointLModelFilePath = moduleShareDirectory + "/" + AVATAR_HANDPOINTL_MODEL_NAME + ".stl";
vtkMRMLModelNode* handPointLModelNode = modelsLogic->AddModel(handPointLModelFilePath.c_str());

// Right hand
std::string handPointRModelFilePath = moduleShareDirectory + "/" + AVATAR_HANDPOINTR_MODEL_NAME + ".stl";
vtkMRMLModelNode* handPointRModelNode = modelsLogic->AddModel(handPointRModelFilePath.c_str());

// Apply transforms
vtkMRMLLinearTransformNode* transformHeadNode = vtkMRMLLinearTransformNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName("VirtualReality.HMD"));
headModelNode->SetAndObserveTransformNodeID(transformHeadNode->GetID());
vtkMRMLLinearTransformNode* transformHandLNode = vtkMRMLLinearTransformNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName("VirtualReality.LeftController"));
handPointLModelNode->SetAndObserveTransformNodeID(transformHandLNode->GetID());
vtkMRMLLinearTransformNode* transformHandRNode = vtkMRMLLinearTransformNode::SafeDownCast(this->GetMRMLScene()->GetFirstNodeByName("VirtualReality.RightController"));
handPointRModelNode->SetAndObserveTransformNodeID(transformHandRNode->GetID());

}

0 comments on commit d2b842d

Please sign in to comment.