HRESULT CDelay::InternalGetInputType(DWORD dwInputStreamIndex, DWORD dwTypeIndex, DMO_MEDIA_TYPE *pmt) { if (dwTypeIndex != 0) { return DMO_E_NO_MORE_ITEMS; } // if pmt is NULL, we just return S_OK if the type index is in range if (pmt == NULL) { return S_OK; } if (OutputTypeSet(0)) // If the input type is set, we prefer that one { return MoCopyMediaType(pmt, OutputType(0)); } else { // if output type is not set, propose something we like return GetPcmType(pmt); } }
HRESULT CDelay::InternalGetOutputSizeInfo(DWORD dwOutputStreamIndex, DWORD *pcbSize, DWORD *pcbAlignment) { // IMediaObjectImpl validates this for us... _ASSERTE(OutputTypeSet(dwOutputStreamIndex)); // And we expect only PCM audio types. _ASSERTE(OutputType(dwOutputStreamIndex)->formattype == FORMAT_WaveFormatEx); WAVEFORMATEX *pWave = (WAVEFORMATEX*)OutputType(dwOutputStreamIndex)->pbFormat; *pcbSize = pWave->nBlockAlign; *pcbAlignment = 1; return S_OK; }
void mitk::ClippedSurfaceBoundsCalculator::Update() { this->m_MinMaxOutput.clear(); m_MinMaxOutput.reserve(3); for(int i = 0; i < 3; i++) { this->m_MinMaxOutput.push_back(OutputType( std::numeric_limits<int>::max() , std::numeric_limits<int>::min() )); } if(m_PlaneGeometry.IsNotNull()) { this->CalculateIntersectionPoints(m_PlaneGeometry); } else if(m_Geometry3D.IsNotNull()) { // go through all slices of the image, ... const mitk::SlicedGeometry3D* slicedGeometry3D = dynamic_cast<const mitk::SlicedGeometry3D*>( m_Geometry3D.GetPointer() ); int allSlices = slicedGeometry3D->GetSlices(); this->CalculateIntersectionPoints(dynamic_cast<mitk::PlaneGeometry*>(slicedGeometry3D->GetPlaneGeometry(0))); this->CalculateIntersectionPoints(dynamic_cast<mitk::PlaneGeometry*>(slicedGeometry3D->GetPlaneGeometry(allSlices-1))); } else if( !m_ObjectPointsInWorldCoordinates.empty() ) { this->CalculateIntersectionPoints( m_ObjectPointsInWorldCoordinates ); this->EnforceImageBounds(); } }
///////////////////////////////// // // IMediaObjectImpl::InternalGetInputType // // *** Called by GetInputType, description below *** // // The GetInputType method retrieves a preferred media type for a specified // input stream. // // Parameters // // dwInputStreamIndex // Zero-based index of an input stream on the DMO. // // dwTypeIndex // Zero-based index on the set of acceptable media types. // // pmt // [out] Pointer to a DMO_MEDIA_TYPE structure allocated by the caller. // The method fills the structure with the media type. The format block // might be NULL, in which case the format type GUID is GUID_NULL. // // Return Value // S_OK Success // DMO_E_INVALIDSTREAMINDEX Invalid stream index // DMO_E_NO_MORE_ITEMS Type index is out of range // E_OUTOFMEMORY Insufficient memory // E_POINTER NULL pointer argument // // Call this method to enumerate an input stream's preferred media types. The // DMO assigns each media type an index value in order of preference. The most // preferred type has an index of zero. To enumerate all the types, make // successive calls while incrementing the type index until the method returns // DMO_E_NO_MORE_ITEMS. // // If the method succeeds, call MoFreeMediaType to free the format block. // // To set the media type, call the SetInputType method. Setting the media type // on one stream can change another stream's preferred types. In fact, a // stream might not have a preferred type until the type is set on another // stream. For example, a decoder might not have a preferred output type until // the input type is set. However, the DMO is not required to update its // preferred types dynamically in this fashion. Thus, the types returned by // this method are not guaranteed to be valid; they might fail when used in the // SetInputType method. Conversely, the DMO is not guaranteed to enumerate every // media type that it supports. To test whether a particular media type is // acceptable, call SetInputType with the DMO_SET_TYPEF_TEST_ONLY flag. // HRESULT CHXAudioDeviceHookBase::InternalGetInputType(DWORD dwInputStreamIndex, DWORD dwTypeIndex, DMO_MEDIA_TYPE *pmt) { // This function resembles InternalGetOutputType() since the input and output types must // be consistent for DirectSound HRESULT hr = S_OK; if (dwTypeIndex > 0) { return DMO_E_NO_MORE_ITEMS; } // If pmt is NULL, and the type index is in range, we return S_OK if (pmt == NULL) { return S_OK; } // If the output type is set, we prefer to use that one if (OutputTypeSet(0)) { return MoCopyMediaType(pmt, OutputType(0)); } hr = MoInitMediaType(pmt, sizeof(WAVEFORMATEX)); if (SUCCEEDED(hr)) { pmt->majortype = MEDIATYPE_Audio; pmt->subtype = MEDIASUBTYPE_PCM; // We take PCM format! pmt->formattype = FORMAT_None; } return hr; }
void mitk::ClippedSurfaceBoundsCalculator::InitializeOutput() { // initialize with meaningless slice indices m_MinMaxOutput.clear(); for(int i = 0; i < 3; i++) { m_MinMaxOutput.push_back( OutputType( std::numeric_limits<int>::max() , std::numeric_limits<int>::min() )); } }
////////////////////////////////////// // // IMediaObjectImpl::InternalGetOutputSizeInfo // // *** Called by GetOutputSizeInfo, description below *** // // The GetOutputSizeInfo method retrieves the buffer requirements for a // specified output stream. // // Parameters // // dwOutputStreamIndex // Zero-based index of an output stream on the DMO. // // pcbSize // [out] Pointer to a variable that receives the minimum size of an // output buffer for this stream, in bytes. // // pulSizeAlignment // [out] Pointer to a variable that receives the required buffer // alignment, in bytes. If the output stream has no alignment // requirement, the value is 1. // // Return Value // S_OK Success // DMO_E_INVALIDSTREAMINDEX Invalid stream index // DMO_E_TYPE_NOT_SET Media type was not set // // The buffer requirements may depend on the media types set for each of the // streams. // // Before calling this method, set the media type of each stream by calling // the SetInputType and SetOutputType methods. If the media types have not // been set, this method might return an error. However, if a stream is // optional, and the application will not use the stream, you do not have to // set the media type for the stream. // // A buffer is aligned if the buffer's start address is a multiple of // *pulSizeAlignment. Depending on the architecture of the microprocessor, it is // faster to read and write to an aligned buffer than to an unaligned buffer. // On some microprocessors, reading and writing to an unaligned buffer is not // supported and can cause the program to crash. Zero is not a valid alignment. // // Note: // // GetOutputSizeInfo returns DMO_E_TYPE_NOT_SET unless all of the non-optional // streams have media types. Therefore, in the derived class, the internal // methods can assume that all of the non-optional streams have media types. // HRESULT CHXAudioDeviceHookBase::InternalGetOutputSizeInfo(DWORD dwOutputStreamIndex, DWORD *pcbSize, DWORD *pulSizeAlignment) { // We don't have to do any validation, because it is all done in the base class HRESULT hr = S_OK; const DMO_MEDIA_TYPE* pmt; pmt = OutputType(0); const WAVEFORMATEX* pwfx = reinterpret_cast<const WAVEFORMATEX*>(pmt->pbFormat); *pcbSize = pwfx->nChannels * pwfx->wBitsPerSample / 8; *pulSizeAlignment = 1; return hr; }
STDMETHODIMP CDelay::Clone(IMediaObjectInPlace **ppMediaObject) { HRESULT hr; if (!ppMediaObject) { return E_POINTER; } *ppMediaObject = NULL; // Make a new one CDelay *pTemp = new CComObject<CDelay>; if (!pTemp) { return E_OUTOFMEMORY; } // Set the media types CComQIPtr<IMediaObject, &IID_IMediaObject> pMediaObj(pTemp); _ASSERTE(pMediaObj != NULL); if (InputTypeSet(0)) { hr = pMediaObj->SetInputType(0, InputType(0), 0); if (FAILED(hr)) { return hr; } } if (OutputTypeSet(0)) { hr = pMediaObj->SetOutputType(0, OutputType(0), 0); if (FAILED(hr)) { return hr; } } // Everything is OK, return the AddRef'd pointer. return pTemp->QueryInterface(IID_IMediaObjectInPlace, (void**)ppMediaObject); }
HRESULT CDMODecoder::InternalAllocateStreamingResources() { LOGPRINTF("%p CDMODecoder::InternalAllocateStreamingResources()", this); const DMO_MEDIA_TYPE *pmtIn = InputType(0); const DMO_MEDIA_TYPE *pmtOut = OutputType(0); const VIDEOINFOHEADER *pvihIn = (const VIDEOINFOHEADER *)pmtIn->pbFormat; const VIDEOINFOHEADER *pvihOut = (const VIDEOINFOHEADER *)pmtOut->pbFormat; utvf_t outfmt; if (DirectShowFormatToUtVideoFormat(&outfmt, pvihOut->bmiHeader.biCompression, pvihOut->bmiHeader.biBitCount, pmtOut->subtype) != 0) return DMO_E_INVALIDTYPE; if (m_pCodec->DecodeBegin(outfmt, pvihOut->bmiHeader.biWidth, pvihOut->bmiHeader.biHeight, CBGROSSWIDTH_WINDOWS, ((BYTE *)&pvihIn->bmiHeader) + sizeof(BITMAPINFOHEADER), pvihIn->bmiHeader.biSize - sizeof(BITMAPINFOHEADER)) == 0) return S_OK; else return E_FAIL; }
HRESULT CDelay::InternalCheckOutputType(DWORD dwOutputStreamIndex, const DMO_MEDIA_TYPE *pmt) { // If our output type is already set, reject format changes if (OutputTypeSet(dwOutputStreamIndex) && !TypesMatch(pmt, OutputType(dwOutputStreamIndex))) { return DMO_E_INVALIDTYPE; } // If our input type is already set, the output type must match else if (InputTypeSet(dwOutputStreamIndex) && !TypesMatch(pmt, InputType(dwOutputStreamIndex))) { return DMO_E_INVALIDTYPE; } // If no types are set yet, validate the format else { return CheckPcmFormat(pmt); } }
//////////////////////////////////// // // IMediaObjectImpl::InternalCheckInputType // // Queries whether an input stream can accept a given media type. // The derived class must declare and implement this method. // // Parameters // // dwInputStreamIndex // Index of an input stream. // // pmt // Pointer to a DMO_MEDIA_TYPE structure that describes the media type. // // Return Value // // Returns S_OK if the media type is valid, or DMO_E_INVALIDTYPE otherwise. // // Note: // // Called by IMediaObject::SetInputType // HRESULT CHXAudioDeviceHookBase::InternalCheckInputType(DWORD dwInputStreamIndex, const DMO_MEDIA_TYPE *pmt) { WAVEFORMATEX* pWave = (WAVEFORMATEX*)pmt->pbFormat; HRESULT hr = S_OK; // Check that we're PCM or float if ((NULL == pmt) || (MEDIATYPE_Audio != pmt->majortype) || (MEDIASUBTYPE_PCM != pmt->subtype) || (FORMAT_WaveFormatEx != pmt->formattype && FORMAT_None != pmt->formattype) || (pmt->cbFormat < sizeof(WAVEFORMATEX)) || (NULL == pmt->pbFormat)) { hr = DMO_E_INVALIDTYPE; } // If other type set, accept only if identical to that. Otherwise accept // any standard PCM/float audio. if (SUCCEEDED(hr)) { if (OutputTypeSet(0)) { const DMO_MEDIA_TYPE* pmtOutput; pmtOutput = OutputType(0); if (memcmp(pmt->pbFormat, pmtOutput->pbFormat, sizeof(WAVEFORMATEX))) { hr = DMO_E_INVALIDTYPE; } } else { WAVEFORMATEX* pWave = (WAVEFORMATEX*)pmt->pbFormat; if ((WAVE_FORMAT_PCM != pWave->wFormatTag) || ((8 != pWave->wBitsPerSample) && (16 != pWave->wBitsPerSample)) || ((1 != pWave->nChannels) && (2 != pWave->nChannels)) || ( // Supported sample rates: (96000 != pWave->nSamplesPerSec) && (48000 != pWave->nSamplesPerSec) && (44100 != pWave->nSamplesPerSec) && (32000 != pWave->nSamplesPerSec) && (22050 != pWave->nSamplesPerSec) && (16000 != pWave->nSamplesPerSec) && (11025 != pWave->nSamplesPerSec) && (8000 != pWave->nSamplesPerSec) && TRUE // You may delete && TRUE ) || (pWave->nBlockAlign != pWave->nChannels * pWave->wBitsPerSample / 8) || (pWave->nAvgBytesPerSec != pWave->nSamplesPerSec * pWave->nBlockAlign)) { hr = DMO_E_INVALIDTYPE; } } } if (SUCCEEDED(hr)) { // We will remember the number of channels, bps, and sample rate of the input type m_nChannels = pWave->nChannels; m_wBitsPerSample = pWave->wBitsPerSample; m_nSamplesPerSec = pWave->nSamplesPerSec; } return hr; }
void test_union(std::string const& caseid, G1 const& g1, G2 const& g2, int expected_count, int expected_hole_count, int expected_point_count, double expected_area, ut_settings const& settings) { typedef typename bg::coordinate_type<G1>::type coordinate_type; boost::ignore_unused<coordinate_type>(); boost::ignore_unused(expected_point_count); // Declare output (vector of rings, or vector of polygons) std::vector<OutputType> clip; #if defined(BOOST_GEOMETRY_DEBUG_ROBUSTNESS) std::cout << "*** UNION " << caseid << std::endl; #endif bg::union_(g1, g2, clip); typename bg::default_area_result<OutputType>::type area = 0; std::size_t n = 0; std::size_t holes = 0; for (typename std::vector<OutputType>::iterator it = clip.begin(); it != clip.end(); ++it) { area += bg::area(*it); holes += bg::num_interior_rings(*it); n += bg::num_points(*it, true); if (settings.test_validity) { // Check validity (currently on separate clips only) // std::cout << bg::dsv(*it) << std::endl; std::string message; bool const valid = bg::is_valid(*it, message); BOOST_CHECK_MESSAGE(valid, "union: " << caseid << " not valid " << message); } } #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE) { // Test inserter functionality // Test if inserter returns output-iterator (using Boost.Range copy) std::vector<OutputType> inserted, array_with_one_empty_geometry; array_with_one_empty_geometry.push_back(OutputType()); boost::copy(array_with_one_empty_geometry, bg::detail::union_::union_insert<OutputType>(g1, g2, std::back_inserter(inserted))); typename bg::default_area_result<OutputType>::type area_inserted = 0; int index = 0; for (typename std::vector<OutputType>::iterator it = inserted.begin(); it != inserted.end(); ++it, ++index) { // Skip the empty polygon created above to avoid the empty_input_exception if (! bg::is_empty(*it)) { area_inserted += bg::area(*it); } } BOOST_CHECK_EQUAL(boost::size(clip), boost::size(inserted) - 1); BOOST_CHECK_CLOSE(area_inserted, expected_area, settings.percentage); } #endif #if defined(BOOST_GEOMETRY_DEBUG_ROBUSTNESS) std::cout << "*** case: " << caseid << " area: " << area << " points: " << n << " polygons: " << boost::size(clip) << " holes: " << holes << std::endl; #endif BOOST_CHECK_MESSAGE(expected_count < 0 || int(clip.size()) == expected_count, "union: " << caseid << " #clips expected: " << expected_count << " detected: " << clip.size() << " type: " << (type_for_assert_message<G1, G2>()) ); BOOST_CHECK_MESSAGE(expected_hole_count < 0 || int(holes) == expected_hole_count, "union: " << caseid << " #holes expected: " << expected_hole_count << " detected: " << holes << " type: " << (type_for_assert_message<G1, G2>()) ); #if ! defined(BOOST_GEOMETRY_NO_ROBUSTNESS) BOOST_CHECK_MESSAGE(expected_point_count < 0 || std::abs(int(n) - expected_point_count) < 3, "union: " << caseid << " #points expected: " << expected_point_count << " detected: " << n << " type: " << (type_for_assert_message<G1, G2>()) ); #endif BOOST_CHECK_CLOSE(area, expected_area, settings.percentage); #if defined(TEST_WITH_SVG) { bool const ccw = bg::point_order<G1>::value == bg::counterclockwise || bg::point_order<G2>::value == bg::counterclockwise; bool const open = bg::closure<G1>::value == bg::open || bg::closure<G2>::value == bg::open; std::ostringstream filename; filename << "union_" << caseid << "_" << string_from_type<coordinate_type>::name() << (ccw ? "_ccw" : "") << (open ? "_open" : "") #if defined(BOOST_GEOMETRY_NO_ROBUSTNESS) << "_no_rob" #endif << ".svg"; std::ofstream svg(filename.str().c_str()); bg::svg_mapper < typename bg::point_type<G2>::type > mapper(svg, 500, 500); mapper.add(g1); mapper.add(g2); mapper.map(g1, "fill-opacity:0.5;fill:rgb(153,204,0);" "stroke:rgb(153,204,0);stroke-width:3"); mapper.map(g2, "fill-opacity:0.3;fill:rgb(51,51,153);" "stroke:rgb(51,51,153);stroke-width:3"); //mapper.map(g1, "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1"); //mapper.map(g2, "opacity:0.6;fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1"); for (typename std::vector<OutputType>::const_iterator it = clip.begin(); it != clip.end(); ++it) { mapper.map(*it, "fill-opacity:0.2;stroke-opacity:0.4;fill:rgb(255,0,0);" "stroke:rgb(255,0,255);stroke-width:8"); //mapper.map(*it, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:5"); } } #endif }
OutputType operator()( tbb::flow::continue_msg ) { ++global_execute_count; ++local_execute_count; return OutputType(); }
std::string test_difference(std::string const& caseid, G1 const& g1, G2 const& g2, int expected_count, int expected_rings_count, int expected_point_count, double expected_area, bool sym, ut_settings const& settings) { typedef typename bg::coordinate_type<G1>::type coordinate_type; boost::ignore_unused<coordinate_type>(); bg::model::multi_polygon<OutputType> result; if (sym) { bg::sym_difference(g1, g2, result); } else { bg::difference(g1, g2, result); } if (settings.remove_spikes) { bg::remove_spikes(result); } #if ! defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE) { bg::model::multi_polygon<OutputType> result_s; typedef typename bg::strategy::relate::services::default_strategy < G1, G2 >::type strategy_type; if (sym) { bg::sym_difference(g1, g2, result_s, strategy_type()); } else { bg::difference(g1, g2, result_s, strategy_type()); } if (settings.remove_spikes) { bg::remove_spikes(result_s); } BOOST_CHECK_EQUAL(bg::num_points(result), bg::num_points(result_s)); } #endif std::ostringstream return_string; return_string << bg::wkt(result); typename bg::default_area_result<G1>::type const area = bg::area(result); std::size_t const n = expected_point_count >= 0 ? bg::num_points(result) : 0; #if ! defined(BOOST_GEOMETRY_NO_BOOST_TEST) if (settings.test_validity) { // std::cout << bg::dsv(result) << std::endl; std::string message; bool const valid = bg::is_valid(result, message); BOOST_CHECK_MESSAGE(valid, "difference: " << caseid << " not valid " << message << " type: " << (type_for_assert_message<G1, G2>())); } #endif difference_output(caseid, g1, g2, result); #if ! (defined(BOOST_GEOMETRY_TEST_ONLY_ONE_TYPE) \ || defined(BOOST_GEOMETRY_DEBUG_ASSEMBLE)) { // Test inserter functionality // Test if inserter returns output-iterator (using Boost.Range copy) typedef typename bg::point_type<G1>::type point_type; typedef typename bg::rescale_policy_type<point_type>::type rescale_policy_type; rescale_policy_type rescale_policy = bg::get_rescale_policy<rescale_policy_type>(g1, g2); typename setop_output_type<OutputType>::type inserted, array_with_one_empty_geometry; array_with_one_empty_geometry.push_back(OutputType()); if (sym) { boost::copy(array_with_one_empty_geometry, bg::detail::sym_difference::sym_difference_insert<OutputType> (g1, g2, rescale_policy, std::back_inserter(inserted))); } else { boost::copy(array_with_one_empty_geometry, bg::detail::difference::difference_insert<OutputType>( g1, g2, rescale_policy, std::back_inserter(inserted))); } BOOST_CHECK_EQUAL(boost::size(result), boost::size(inserted) - 1); } #endif #if ! defined(BOOST_GEOMETRY_NO_BOOST_TEST) if (expected_point_count >= 0) { BOOST_CHECK_MESSAGE(bg::math::abs(int(n) - expected_point_count) < 3, "difference: " << caseid << " #points expected: " << expected_point_count << " detected: " << n << " type: " << (type_for_assert_message<G1, G2>()) ); } if (expected_count >= 0) { BOOST_CHECK_MESSAGE(int(boost::size(result)) == expected_count, "difference: " << caseid << " #outputs expected: " << expected_count << " detected: " << result.size() << " type: " << (type_for_assert_message<G1, G2>()) ); } if (expected_rings_count >= 0) { int nrings = int(boost::size(result) + bg::num_interior_rings(result)); BOOST_CHECK_MESSAGE(nrings == expected_rings_count, "difference: " << caseid << " #rings expected: " << expected_rings_count << " detected: " << nrings << " type: " << (type_for_assert_message<G1, G2>()) ); } BOOST_CHECK_CLOSE(area, expected_area, settings.percentage); #endif return return_string.str(); }
void test_difference(std::string const& caseid, G1 const& g1, G2 const& g2, int expected_count, int expected_point_count, double expected_area, double percentage = 0.0001, bool sym = false) { typedef typename bg::coordinate_type<G1>::type coordinate_type; boost::ignore_unused<coordinate_type>(); std::vector<OutputType> clip; if (sym) { bg::sym_difference(g1, g2, clip); } else { bg::difference(g1, g2, clip); } typename bg::default_area_result<G1>::type area = 0; int n = 0; for (typename std::vector<OutputType>::iterator it = clip.begin(); it != clip.end(); ++it) { if (expected_point_count >= 0) { n += bg::num_points(*it); } area += bg::area(*it); } difference_output(caseid, g1, g2, clip); #ifndef BOOST_GEOMETRY_DEBUG_ASSEMBLE { // Test inserter functionality // Test if inserter returns output-iterator (using Boost.Range copy) typedef typename bg::point_type<G1>::type point_type; typedef typename bg::rescale_policy_type<point_type>::type rescale_policy_type; rescale_policy_type rescale_policy = bg::get_rescale_policy<rescale_policy_type>(g1, g2); std::vector<OutputType> inserted, array_with_one_empty_geometry; array_with_one_empty_geometry.push_back(OutputType()); if (sym) { boost::copy(array_with_one_empty_geometry, bg::detail::sym_difference::sym_difference_insert<OutputType> (g1, g2, rescale_policy, std::back_inserter(inserted))); } else { boost::copy(array_with_one_empty_geometry, bg::detail::difference::difference_insert<OutputType>( g1, g2, rescale_policy, std::back_inserter(inserted))); } BOOST_CHECK_EQUAL(boost::size(clip), boost::size(inserted) - 1); } #endif #if ! defined(BOOST_GEOMETRY_NO_BOOST_TEST) if (expected_point_count >= 0) { BOOST_CHECK_MESSAGE(bg::math::abs(n - expected_point_count) < 3, "difference: " << caseid << " #points expected: " << expected_point_count << " detected: " << n << " type: " << (type_for_assert_message<G1, G2>()) ); } if (expected_count >= 0) { BOOST_CHECK_MESSAGE(int(clip.size()) == expected_count, "difference: " << caseid << " #outputs expected: " << expected_count << " detected: " << clip.size() << " type: " << (type_for_assert_message<G1, G2>()) ); } BOOST_CHECK_CLOSE(area, expected_area, percentage); #endif }
void test_union(std::string const& caseid, G1 const& g1, G2 const& g2, std::size_t expected_count, std::size_t expected_hole_count, int expected_point_count, double expected_area, double percentage) { typedef typename bg::coordinate_type<G1>::type coordinate_type; std::vector<OutputType> clip; bg::union_(g1, g2, clip); typename bg::default_area_result<G1>::type area = 0; std::size_t n = 0; std::size_t holes = 0; for (typename std::vector<OutputType>::iterator it = clip.begin(); it != clip.end(); ++it) { area += bg::area(*it); holes += bg::num_interior_rings(*it); n += bg::num_points(*it, true); } { // Test inserter functionality // Test if inserter returns output-iterator (using Boost.Range copy) std::vector<OutputType> inserted, array_with_one_empty_geometry; array_with_one_empty_geometry.push_back(OutputType()); boost::copy(array_with_one_empty_geometry, bg::detail::union_::union_insert<OutputType>(g1, g2, std::back_inserter(inserted))); typename bg::default_area_result<G1>::type area_inserted = 0; int index = 0; for (typename std::vector<OutputType>::iterator it = inserted.begin(); it != inserted.end(); ++it, ++index) { // Skip the empty polygon created above to avoid the empty_input_exception if (bg::num_points(*it) > 0) { area_inserted += bg::area(*it); } } BOOST_CHECK_EQUAL(boost::size(clip), boost::size(inserted) - 1); BOOST_CHECK_CLOSE(area_inserted, expected_area, percentage); } /*** std::cout << "case: " << caseid << " n: " << n << " area: " << area << " polygons: " << boost::size(clip) << " holes: " << holes << std::endl; ***/ if (expected_point_count >= 0) { BOOST_CHECK_MESSAGE(n == std::size_t(expected_point_count), "union: " << caseid << " #points expected: " << expected_point_count << " detected: " << n << " type: " << (type_for_assert_message<G1, G2>()) ); } BOOST_CHECK_EQUAL(clip.size(), expected_count); BOOST_CHECK_EQUAL(holes, expected_hole_count); BOOST_CHECK_CLOSE(area, expected_area, percentage); #if defined(TEST_WITH_SVG) { bool const ccw = bg::point_order<G1>::value == bg::counterclockwise || bg::point_order<G2>::value == bg::counterclockwise; bool const open = bg::closure<G1>::value == bg::open || bg::closure<G2>::value == bg::open; std::ostringstream filename; filename << "union_" << caseid << "_" << string_from_type<coordinate_type>::name() << (ccw ? "_ccw" : "") << (open ? "_open" : "") << ".svg"; std::ofstream svg(filename.str().c_str()); bg::svg_mapper < typename bg::point_type<G2>::type > mapper(svg, 500, 500); mapper.add(g1); mapper.add(g2); mapper.map(g1, "fill-opacity:0.5;fill:rgb(153,204,0);" "stroke:rgb(153,204,0);stroke-width:3"); mapper.map(g2, "fill-opacity:0.3;fill:rgb(51,51,153);" "stroke:rgb(51,51,153);stroke-width:3"); //mapper.map(g1, "opacity:0.6;fill:rgb(0,0,255);stroke:rgb(0,0,0);stroke-width:1"); //mapper.map(g2, "opacity:0.6;fill:rgb(0,255,0);stroke:rgb(0,0,0);stroke-width:1"); for (typename std::vector<OutputType>::const_iterator it = clip.begin(); it != clip.end(); ++it) { mapper.map(*it, "fill-opacity:0.2;stroke-opacity:0.4;fill:rgb(255,0,0);" "stroke:rgb(255,0,255);stroke-width:8"); //mapper.map(*it, "opacity:0.6;fill:none;stroke:rgb(255,0,0);stroke-width:5"); } } #endif }
CmCError CheckSyntax(char *filename, CmCParser *synParser) { //***************************************** //parse the file //***************************************** int error; synParser->SetDelimiters("=(){},;'"); synParser->StoreDelimiters(true); error = synParser->Parse(filename); if(error) return (CmCError((CmCToken *) NULL, SYN_INVALID_FILE)); //***************************************** //check syntax //***************************************** int curveId; int parameterId; int commandTypeId, commandId; CmCToken *token, *(tokenSet)[MAX_TOKEN_NUM]; while(token = synParser->GetToken()) { //identify the command... commandId = Command(token->token_); commandTypeId = CommandType(commandId); //based on the command, identify the number of tokens //associated with it and obtain those tokens error = GetTokenSet(commandId, tokenSet, synParser); //if the specified number of tokens does not exist //then return an error if(error == SYN_ERROR) return CmCError((CmCToken *) NULL, error); //if the specified tokens exist, then check them for //their validity switch(commandTypeId) { case CMD_IO: switch(commandId) { case CMD_SAVE: //check structure if(strcmp(tokenSet[0]->token_, "(")) return CmCError(tokenSet[0], SYN_MISSING_LEFT_PARENTHESIS); if(strcmp(tokenSet[1]->token_, "'")) return CmCError(tokenSet[1],SYN_MISSING_QUOTATION); if(strcmp(tokenSet[3]->token_, "'")) return CmCError(tokenSet[3],SYN_MISSING_QUOTATION); if(strcmp(tokenSet[4]->token_, ",")) return CmCError(tokenSet[4],SYN_MISSING_COMMA); if(strcmp(tokenSet[6]->token_, ",")) return CmCError(tokenSet[6],SYN_MISSING_COMMA); if(strcmp(tokenSet[8]->token_, ")")) return CmCError(tokenSet[8],SYN_MISSING_RIGHT_PARENTHESIS); if(strcmp(tokenSet[9]->token_, ";")) return CmCError(tokenSet[9],SYN_MISSING_SEMICOLON); //check constants if(!validFileType(tokenSet[5]->token_)) return CmCError(tokenSet[5],SYN_INVALID_FILETYPE); if(!validOutputType(tokenSet[7]->token_))return CmCError(tokenSet[7],SYN_INVALID_OUTPUTTYPE); if(checkSupported(FileType(tokenSet[5]->token_))) return CmCError(tokenSet[5],SYN_UNSUPPORTED_FILETYPE); break; case CMD_LOAD: //check structure if(strcmp(tokenSet[0]->token_, "(")) return CmCError(tokenSet[0],SYN_MISSING_LEFT_PARENTHESIS); if(strcmp(tokenSet[1]->token_, "'")) return CmCError(tokenSet[1],SYN_MISSING_QUOTATION); if(strcmp(tokenSet[3]->token_, "'")) return CmCError(tokenSet[3],SYN_MISSING_QUOTATION); if(strcmp(tokenSet[4]->token_, ",")) return CmCError(tokenSet[4],SYN_MISSING_COMMA); if(strcmp(tokenSet[6]->token_, ")")) return CmCError(tokenSet[6],SYN_MISSING_RIGHT_PARENTHESIS); if(strcmp(tokenSet[7]->token_, ";")) return CmCError(tokenSet[7],SYN_MISSING_SEMICOLON); //check constants if(!validInputType(tokenSet[5]->token_)) return CmCError(tokenSet[5],SYN_INVALID_INPUTTYPE); break; case CMD_USE_RESULT: if(strcmp(tokenSet[0]->token_, "(")) return CmCError(tokenSet[0], SYN_MISSING_LEFT_PARENTHESIS); if(strcmp(tokenSet[2]->token_, ")")) return CmCError(tokenSet[2], SYN_MISSING_RIGHT_PARENTHESIS); if(strcmp(tokenSet[3]->token_, ";")) return CmCError(tokenSet[3], SYN_MISSING_SEMICOLON); if((OutputType(tokenSet[1]->token_) != OUTPUT_SEGM_IMAGE) && (OutputType(tokenSet[1]->token_) != OUTPUT_FILT_IMAGE)) { if(OutputType(tokenSet[1]->token_) != OUTPUT_UNKNOWN) { return CmCError(tokenSet[1], SYN_ASSIGN_INVALID_ARG); } else { return CmCError(tokenSet[1], SYN_INVALID_OUTPUTTYPE); } } break; } break; case CMD_EXECUTION: if(tokenSet[0]->token_[0] != ';') return CmCError(tokenSet[0],SYN_MISSING_SEMICOLON); break; case CMD_FLAGS: if(!validFlag(tokenSet[0]->token_)) return CmCError(tokenSet[0],SYN_INVALID_FLAG); if(tokenSet[1]->token_[0] != ';') return CmCError(tokenSet[1],SYN_MISSING_SEMICOLON); break; //unknown command default: break; } //if its not a command, then maybe its a parameter if(commandTypeId == UNKNOWN_COMMAND) { //get the parameter type parameterId = Parameter(token->token_); if(parameterId != UNKNOWN_PARAMETER) { //retreive tokens expected given a parameter error = GetParamTokenSet(tokenSet, synParser); if(error == SYN_ERROR) return CmCError(token, SYN_ERROR); //check those tokens for validity if(strcmp(tokenSet[0]->token_, "=")) return CmCError(tokenSet[0],SYN_MISSING_EQUALS); if(strcmp(tokenSet[2]->token_, ";")) return CmCError(tokenSet[2],SYN_MISSING_SEMICOLON); //make sure parameter is of the right type error = CheckParameter(parameterId, tokenSet[1]->token_); if(error) return CmCError(token, error); //if its an unknown parameter then maybe its a curve list } else { //get custom curve curveId = CustomCurve(token->token_); //if its not a custom curve list then flag an error if(curveId == UNKNOWN_CURVE) return CmCError(token,SYN_INVALID_PARAMCMD); //check for equals token = synParser->GetToken(); if(token->token_[0] != '=') return CmCError(token,SYN_MISSING_EQUALS); //if its a curve list, then check that a proper point list //is provided error = CheckList(synParser, &token); if(error) return CmCError(token, error); //check for semicolon token = synParser->GetToken(); if(token->token_[0] != ';') return CmCError(token,SYN_MISSING_SEMICOLON); } } //command/parameter identified and verified for //its validity, next command/parameter } //reset parser synParser->StartOver(); //file is syntaxically correct return CmCError((CmCToken *) NULL, NO_ERRORS); }
void HistogramAttributes::SetFromNode(DataNode *parentNode) { if(parentNode == 0) return; DataNode *searchNode = parentNode->GetNode("HistogramAttributes"); if(searchNode == 0) return; DataNode *node; if((node = searchNode->GetNode("basedOn")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 2) SetBasedOn(BasedOn(ival)); } else if(node->GetNodeType() == STRING_NODE) { BasedOn value; if(BasedOn_FromString(node->AsString(), value)) SetBasedOn(value); } } if((node = searchNode->GetNode("histogramType")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 3) SetHistogramType(BinContribution(ival)); } else if(node->GetNodeType() == STRING_NODE) { BinContribution value; if(BinContribution_FromString(node->AsString(), value)) SetHistogramType(value); } } if((node = searchNode->GetNode("weightVariable")) != 0) SetWeightVariable(node->AsString()); if((node = searchNode->GetNode("limitsMode")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 2) SetLimitsMode(LimitsMode(ival)); } else if(node->GetNodeType() == STRING_NODE) { LimitsMode value; if(LimitsMode_FromString(node->AsString(), value)) SetLimitsMode(value); } } if((node = searchNode->GetNode("minFlag")) != 0) SetMinFlag(node->AsBool()); if((node = searchNode->GetNode("maxFlag")) != 0) SetMaxFlag(node->AsBool()); if((node = searchNode->GetNode("min")) != 0) SetMin(node->AsDouble()); if((node = searchNode->GetNode("max")) != 0) SetMax(node->AsDouble()); if((node = searchNode->GetNode("numBins")) != 0) SetNumBins(node->AsInt()); if((node = searchNode->GetNode("domain")) != 0) SetDomain(node->AsInt()); if((node = searchNode->GetNode("zone")) != 0) SetZone(node->AsInt()); if((node = searchNode->GetNode("useBinWidths")) != 0) SetUseBinWidths(node->AsBool()); if((node = searchNode->GetNode("outputType")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 2) SetOutputType(OutputType(ival)); } else if(node->GetNodeType() == STRING_NODE) { OutputType value; if(OutputType_FromString(node->AsString(), value)) SetOutputType(value); } } if((node = searchNode->GetNode("lineStyle")) != 0) SetLineStyle(node->AsInt()); if((node = searchNode->GetNode("lineWidth")) != 0) SetLineWidth(node->AsInt()); if((node = searchNode->GetNode("color")) != 0) color.SetFromNode(node); if((node = searchNode->GetNode("dataScale")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 3) SetDataScale(DataScale(ival)); } else if(node->GetNodeType() == STRING_NODE) { DataScale value; if(DataScale_FromString(node->AsString(), value)) SetDataScale(value); } } if((node = searchNode->GetNode("binScale")) != 0) { // Allow enums to be int or string in the config file if(node->GetNodeType() == INT_NODE) { int ival = node->AsInt(); if(ival >= 0 && ival < 3) SetBinScale(DataScale(ival)); } else if(node->GetNodeType() == STRING_NODE) { DataScale value; if(DataScale_FromString(node->AsString(), value)) SetBinScale(value); } } if((node = searchNode->GetNode("normalizeHistogram")) != 0) SetNormalizeHistogram(node->AsBool()); if((node = searchNode->GetNode("computeAsCDF")) != 0) SetComputeAsCDF(node->AsBool()); }
void test_difference(std::string const& caseid, G1 const& g1, G2 const& g2, std::size_t expected_count, std::size_t expected_point_count, double expected_area, double percentage = 0.0001, bool sym = false) { std::vector<OutputType> clip; typedef typename bg::coordinate_type<G1>::type coordinate_type; typedef typename bg::point_type<G1>::type point_type; if (sym) { bg::sym_difference(g1, g2, clip); } else { bg::difference(g1, g2, clip); } typename bg::default_area_result<G1>::type area = 0; std::size_t n = 0; for (typename std::vector<OutputType>::iterator it = clip.begin(); it != clip.end(); ++it) { if (expected_point_count > 0) { // Get a correct point-count without duplicate points // (note that overlay might be adapted to avoid duplicates) bg::unique(*it); n += bg::num_points(*it); } area += bg::area(*it); } #ifndef BOOST_GEOMETRY_DEBUG_ASSEMBLE { // Test inserter functionality // Test if inserter returns output-iterator (using Boost.Range copy) std::vector<OutputType> inserted, array_with_one_empty_geometry; array_with_one_empty_geometry.push_back(OutputType()); if (sym) { boost::copy(array_with_one_empty_geometry, bg::detail::sym_difference::sym_difference_insert<OutputType>(g1, g2, std::back_inserter(inserted))); } else { boost::copy(array_with_one_empty_geometry, bg::detail::difference::difference_insert<OutputType>(g1, g2, std::back_inserter(inserted))); } BOOST_CHECK_EQUAL(boost::size(clip), boost::size(inserted) - 1); } #endif #if ! defined(BOOST_GEOMETRY_NO_BOOST_TEST) /*if (expected_point_count > 0) { BOOST_CHECK_MESSAGE(n == expected_point_count, "difference: " << caseid << " #points expected: " << expected_point_count << " detected: " << n << " type: " << string_from_type<coordinate_type>::name() ); }*/ if (expected_count > 0) { BOOST_CHECK_MESSAGE(clip.size() == expected_count, "difference: " << caseid << " #outputs expected: " << expected_count << " detected: " << clip.size() << " type: " << string_from_type<coordinate_type>::name() ); } BOOST_CHECK_CLOSE(area, expected_area, percentage); #endif #if defined(TEST_WITH_SVG) { std::ostringstream filename; filename << "difference_" << caseid << "_" << string_from_type<coordinate_type>::name() << string_from_type<CalculationType>::name() << ".svg"; std::ofstream svg(filename.str().c_str()); bg::svg_mapper<point_type> mapper(svg, 500, 500); mapper.add(g1); mapper.add(g2); mapper.map(g1, "fill-opacity:0.3;fill:rgb(51,51,153);stroke:rgb(51,51,153);stroke-width:3"); mapper.map(g2, "fill-opacity:0.5;fill:rgb(153,204,0);stroke:rgb(153,204,0);stroke-width:3"); for (typename std::vector<OutputType>::const_iterator it = clip.begin(); it != clip.end(); ++it) { mapper.map(*it, //sym ? "fill-opacity:0.2;stroke-opacity:0.4;fill:rgb(255,255,0);stroke:rgb(255,0,255);stroke-width:8" : "fill-opacity:0.2;stroke-opacity:0.4;fill:rgb(255,0,0);stroke:rgb(255,0,255);stroke-width:8"); } } #endif }
void start() { send(OutputType(3, 3.3, 5, 5.4)); }
int EXECUTE(int cmdId, CmCParser *script, void **paramTable) { switch(cmdId) { //*************************************************** //set global flags //*************************************************** case CMD_SYNERGISTIC: { CmCToken *token; token = script->GetToken(); //get flag if(!strcmp(token->token_, "ON")) { CmCSynergistic = true; CmCPrompt("Synergistic Segmentation ENABLED.\n"); } else { CmCSynergistic = false; CmCPrompt("Synergistic Segmentation DISABLED.\n"); } script->GetToken(); //skip ';' break; } case CMD_DISPLAY_PROGRESS: { CmCToken *token; token = script->GetToken(); //get flag if(!strcmp(token->token_, "ON")) CmCDisplayProgress = true; else CmCDisplayProgress = false; script->GetToken(); //skip ';' CmCPrompt("Display progress ENABLED.\n"); break; } case CMD_USE_CUSTOM_WEIGHT_MAP: { CmCToken *token; token = script->GetToken(); //get flag if(!strcmp(token->token_, "ON")) { CmCUseCustomWeightMap = true; CmCPrompt("Custum weight map IN-USE (if defined).\n"); } else { CmCUseCustomWeightMap = false; CmCPrompt("Custum weight map IN-ACTIVE.\n"); } script->GetToken(); //skip ';' break; } //*************************************************** //load a file //*************************************************** case CMD_LOAD: { CmCToken *token; script->GetToken(); //skip "('" script->GetToken(); token = script->GetToken(); //get filename char *filename = new char[strlen(token->token_)+1]; strcpy(filename, token->token_); script->GetToken(); //skip "'," script->GetToken(); token = script->GetToken(); //get input type int inputtype = InputType(token->token_); script->GetToken(); //skip ");" script->GetToken(); //load file int error = edison.Load(filename, inputtype); if(!error) CmCPrompt("File '%s' has been successfully loaded!\n", filename); delete [] filename; //return any errors if(error) return error; break; } //*************************************************** //save a file //*************************************************** case CMD_SAVE: { CmCToken *token; script->GetToken(); //skip "('" script->GetToken(); token = script->GetToken(); //get filename char *filename = new char [strlen(token->token_) + 1]; strcpy(filename, token->token_); script->GetToken(); //skip "'," script->GetToken(); token = script->GetToken(); //filetype int filetype = FileType(token->token_); script->GetToken(); //skip ',' token = script->GetToken(); //get output type int outputtype = OutputType(token->token_); script->GetToken(); //skip ");" script->GetToken(); //save file int error = edison.Save(filename, filetype, outputtype); if(!error) CmCPrompt("File '%s' has been successfully saved!\n", filename); delete [] filename; //return any errors if(error) return error; break; } //*************************************************** //route output to input //*************************************************** case CMD_USE_RESULT: { CmCToken *token; script->GetToken(); //skip '(' token = script->GetToken(); //get output type int outputtype = OutputType(token->token_); script->GetToken(); //skip ");" script->GetToken(); //route output to input int error = edison.UseResult(outputtype); if(!error) { if(outputtype == OUTPUT_SEGM_IMAGE) { CmCPrompt("Segmented image result has been set as input.\n"); } else { CmCPrompt("Filtered image result has been set as input.\n"); } } if(error) return error; break; } //*************************************************** //edge detect the input image //*************************************************** case CMD_EDGE_DETECT: { edison.SetParameters(paramTable); int error = edison.EdgeDetect(); if(error) return error; script->GetToken(); //skip ';' break; } //*************************************************** //filter the input image //*************************************************** case CMD_FILTER: { edison.SetParameters(paramTable); int error = edison.Filter(); if(error) return error; script->GetToken(); //skip ';' break; } //*************************************************** //fuse the regions of the input image //*************************************************** case CMD_FUSE: { edison.SetParameters(paramTable); int error = edison.Fuse(); if(error) return error; script->GetToken(); //skip ';' break; } //*************************************************** //segment the input image //*************************************************** case CMD_SEGMENT: { edison.SetParameters(paramTable); int error = edison.Segment(); if(error) return error; script->GetToken(); //skip ';' break; } //*************************************************** //does nothing //*************************************************** default: break; } //command executed succesfully! return NO_ERRORS; }
HistogramAttributes::OutputType HistogramAttributes::GetOutputType() const { return OutputType(outputType); }
void process(std::tuple<int, double, int, double> tuple){ send(OutputType(std::get<0>(tuple) + std::get<2>(tuple), std::get<1>(tuple) + std::get<3>(tuple))); }