Common Vision Blox 15.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Events Friends Modules Pages
Image Manager/Cvb++/CppSingleStreamComposite

This example program is located in your CVB installation under %CVB%Tutorial/Image Manager/Cvb++/CppSingleStreamComposite.

main.cpp:

// Example for streaming a single composite.
#include <iostream>
#include <string>
#include <vector>
#include <cvb/device_factory.hpp>
#include <cvb/global.hpp>
#include <cvb/driver/composite_stream.hpp>
#include <cvb/genapi/node_map_enumerator.hpp>
static const constexpr auto TIMEOUT = std::chrono::milliseconds(3000);
static const constexpr int NUM_ELEMENTS_TO_ACQUIRE = 10; // number of elements to be acquired
static std::map<Cvb::WaitStatus, const char*>
WAIT_ERROR_STATES
{
{Cvb::WaitStatus::Timeout, "timeout"},
{Cvb::WaitStatus::Abort, "abort"}
};
int main()
{
try
{
// discover transport layers
auto infoList = Cvb::DeviceFactory::Discover(Cvb::DiscoverFlags::IgnoreVins);
// can't continue the demo if there's no available device
if (infoList.empty())
throw std::runtime_error("There is no available device for this demonstration.");
// instantiate the first device in the discovered list
auto device = Cvb::DeviceFactory::Open<Cvb::GenICamDevice>(infoList[0].AccessToken(), Cvb::AcquisitionStack::GenTL);
// access the first data stream that belongs to the device:
auto dataStream = device->Stream<Cvb::CompositeStream>();
// start the data acquisition
dataStream->Start();
// acquire data
for (auto i = 0; i < NUM_ELEMENTS_TO_ACQUIRE; i++)
{
auto [composite, waitStatus, enumerator] = dataStream->WaitFor(TIMEOUT);
switch (waitStatus)
{
default:
std::cout << "wait status unknown.\n";
case Cvb::WaitStatus::Abort:
case Cvb::WaitStatus::Timeout:
{
std::cout << "wait status not ok: " << WAIT_ERROR_STATES[waitStatus] << "\n";
continue;
}
case Cvb::WaitStatus::Ok:
{
break;
}
}
// assume the composites first element is an image
auto firstElement = composite->ItemAt(0);
{
std::cout << "composite does not contain an image at the first element\n";
continue;
}
auto image = Cvb::get<Cvb::ImagePtr>(firstElement);
auto linearAccess = image->Plane(0).LinearAccess();
std::cout << "acquired image: " << i << " at memory location: " << reinterpret_cast<intptr_t>(linearAccess.BasePtr()) << "\n";
}
// stop the data acquisition, ignore errors
dataStream->Stop();
}
catch (const std::exception& e)
{
std::cout << e.what() << std::endl;
}
return 0;
}
void Start() override
static std::vector< DiscoveryInformation > Discover()
static std::shared_ptr< T > Open(const String &provider, AcquisitionStack acquisitionStack=AcquisitionStack::PreferVin)
const variant_alternative_t< I, variant< TS... > > & get(const variant< TS... > &var)
bool holds_alternative(const variant< TS... > &var) noexcept