diff --git a/Modules/US/Testing/mitkUSDeviceTest.cpp b/Modules/US/Testing/mitkUSDeviceTest.cpp index 7dd3fe92a7..c65abce53c 100644 --- a/Modules/US/Testing/mitkUSDeviceTest.cpp +++ b/Modules/US/Testing/mitkUSDeviceTest.cpp @@ -1,82 +1,104 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-02-25 17:27:17 +0100 (Mo, 25 Feb 2008) $ Version: $Revision: 7837 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkUSDevice.h" #include "mitkUSProbe.h" #include "mitkTestingMacros.h" class mitkUSDeviceTestClass { public: // Anm: Implementierung der einzelnen Testmethoden static void TestInstantiation() { // let's create an object of our class mitk::USDevice::Pointer device = mitk::USDevice::New(); MITK_TEST_CONDITION_REQUIRED(device.IsNotNull(), "USDevice should not be null after instantiation"); } static void TestAddProbe() { mitk::USDevice::Pointer device = mitk::USDevice::New(); // create probes mitk::USProbe::Pointer usSource = mitk::USProbe::New(); mitk::USProbe::Pointer probeA = mitk::USProbe::New(); mitk::USProbe::Pointer probeB = mitk::USProbe::New(); mitk::USProbe::Pointer identicalProbe = mitk::USProbe::New(); // only this one should be identical // give my babys some names probeA->SetName("ProbeA"); probeB->SetName("ProbeB"); identicalProbe->SetName("ProbeA"); // I'm gonna be a bad father... //right now, list of devices should be empty MITK_TEST_CONDITION_REQUIRED(device->GetConnectedProbes().size() == 0, "Newly created device should have no probes connected"); // Connect Probe A device->AddProbe(probeA); MITK_TEST_CONDITION_REQUIRED(device->GetConnectedProbes().size() == 1, "Device should add one new probe"); // Connect Probe B device->AddProbe(probeB); MITK_TEST_CONDITION_REQUIRED(device->GetConnectedProbes().size() == 2, "Device should add another probe"); // Connect identical Probe device->AddProbe(identicalProbe); MITK_TEST_CONDITION_REQUIRED(device->GetConnectedProbes().size() == 2, "Device should not have added identical probe"); } + + static void TestActivateProbe() + { + mitk::USDevice::Pointer device = mitk::USDevice::New(); + // create probes + mitk::USProbe::Pointer usSource = mitk::USProbe::New(); + mitk::USProbe::Pointer probeA = mitk::USProbe::New(); + mitk::USProbe::Pointer probeB = mitk::USProbe::New(); + mitk::USProbe::Pointer identicalProbe = mitk::USProbe::New(); // only this one should be identical + + // names + probeA->SetName("ProbeA"); + probeB->SetName("ProbeB"); + identicalProbe->SetName("ProbeA"); + device->AddProbe(probeA); + device->AddProbe(probeB); + + // We after activation, we expect the device to activate probeA, which is the first-connected identical version. + device->ActivateProbe(identicalProbe); + MITK_TEST_CONDITION_REQUIRED(device->GetActiveProbe() == probeA, "probe A should be active"); + } }; /** * This function is testing methods of the class USDevice. */ int mitkUSDeviceTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("mitkUSDeviceTest"); mitkUSDeviceTestClass::TestInstantiation(); mitkUSDeviceTestClass::TestAddProbe(); + mitkUSDeviceTestClass::TestActivateProbe(); MITK_TEST_END(); } \ No newline at end of file diff --git a/Modules/US/USFilters/mitkUSDevice.H b/Modules/US/USFilters/mitkUSDevice.H index 59ed91fb70..a987abf54e 100644 --- a/Modules/US/USFilters/mitkUSDevice.H +++ b/Modules/US/USFilters/mitkUSDevice.H @@ -1,79 +1,81 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKUSDevice_H_HEADER_INCLUDED_ #define MITKUSDevice_H_HEADER_INCLUDED_ #include #include "mitkUSProbe.h" #include #include #include #include namespace mitk { /**Documentation * \brief A device holds information about it's model, make and the connected Probes. It could * \ingroup US */ class MitkUS_EXPORT USDevice : public itk::Object { public: mitkClassMacro(USDevice,itk::Object); itkNewMacro(Self); /** * \brief Add a probe to the device without connecting to it. * This should usually be done before connecting to the probe */ virtual void AddProbe(mitk::USProbe::Pointer probe); /** * \brief Connect to a probe and activate it. The probe should be added first. * Usually, a VideoDevice will just add a probe it want's to connect to, * but an SDK Device might require adding a probe first. */ - //virtual void ActivateProbe(mitk::USProbe probe); + virtual void ActivateProbe(mitk::USProbe::Pointer probe); /** * \brief Deactivates the currently active probe. */ //virtual void DeactivateProbe(); /** * \brief Removes a probe from the ist of currently added probes. */ - //virtual void removeProbe(mitk::USProbe probe); + //virtual void removeProbe(mitk::USProbe::Pointer probe); std::vector GetConnectedProbes(); + itkGetMacro(ActiveProbe, mitk::USProbe::Pointer); + protected: USDevice(); virtual ~USDevice(); mitk::USProbe::Pointer m_ActiveProbe; std::vector m_ConnectedProbes; }; } // namespace mitk #endif \ No newline at end of file diff --git a/Modules/US/USFilters/mitkUSDevice.cpp b/Modules/US/USFilters/mitkUSDevice.cpp index f4f28e3980..d2b785a1dc 100644 --- a/Modules/US/USFilters/mitkUSDevice.cpp +++ b/Modules/US/USFilters/mitkUSDevice.cpp @@ -1,43 +1,55 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkUSDevice.h" mitk::USDevice::USDevice() : itk::Object() { // m_ConnectedProbes = new std::vector(); } mitk::USDevice::~USDevice() { } void mitk::USDevice::AddProbe(mitk::USProbe::Pointer probe) { for(int i = 0; i < m_ConnectedProbes.size(); i++) { if (m_ConnectedProbes[i]->IsEqualToProbe(probe)) return; } this->m_ConnectedProbes.push_back(probe); } +void mitk::USDevice::ActivateProbe(mitk::USProbe::Pointer probe){ + // currently, we can just add the probe. This behaviour must be changed, should more complicated SDK applications emerge + AddProbe(probe); + int index = -1; + for(int i = 0; i < m_ConnectedProbes.size(); i++) + { + if (m_ConnectedProbes[i]->IsEqualToProbe(probe)) index = i; + } + // index now contains the position of the original instance of this probe + m_ActiveProbe = m_ConnectedProbes[index]; +} + std::vector mitk::USDevice::GetConnectedProbes() { return m_ConnectedProbes; } \ No newline at end of file