Exemplo n.º 1
0
void Box::AllocateChildren() const {
    ChildrenCont::const_iterator iter( m_children.begin() );
    ChildrenCont::const_iterator iterend( m_children.end() );
    unsigned int num_expand( 0 );
    unsigned int num_visible( 0 );

    // Count number of visible and expanded children.
    for( ; iter != iterend; ++iter ) {
        if( !IsChildInteresting( iter->widget ) ) {
            continue;
        }

        ++num_visible;

        if( iter->expand ) {
            ++num_expand;
        }
    }

    // Calculate extra width pre expanded widget.
    float extra( 0.f );

    if( num_expand > 0 ) {
        if( m_orientation == HORIZONTAL ) {
            extra = std::max( 0.f, GetAllocation().width - GetRequisition().x ) / static_cast<float>( num_expand );
        }
        else {
            extra = std::max( 0.f, GetAllocation().height - GetRequisition().y ) / static_cast<float>( num_expand );
        }
    }

    // Allocate children.
    float gap( Context::Get().GetEngine().GetProperty<float>( "Gap", shared_from_this() ) );
    sf::Vector2f allocation( 0.f, 0.f );
    sf::Vector2f position( gap, gap );

    for( iter = m_children.begin(); iter != iterend; ++iter ) {
        if( !IsChildInteresting( iter->widget ) ) {
            continue;
        }

        if( m_orientation == HORIZONTAL ) {
            allocation.x = iter->widget->GetRequisition().x + (iter->expand ? extra : 0.f);
            allocation.y = GetAllocation().height - 2 * gap;

            iter->widget->SetAllocation( sf::FloatRect( position.x, position.y, allocation.x - (iter->expand && !iter->fill ? extra : 0.f), allocation.y ) );
            position.x += allocation.x + GetSpacing();
        }
        else {
            allocation.x = GetAllocation().width - 2 * gap;
            allocation.y = iter->widget->GetRequisition().y + (iter->expand ? extra : 0.f);

            iter->widget->SetAllocation( sf::FloatRect( position.x, position.y, allocation.x, allocation.y - (iter->expand && !iter->fill ? extra : 0.f) ) );
            position.y += allocation.y + GetSpacing();
        }

        --num_visible;
    }
}
Exemplo n.º 2
0
// Closes one of the line box's inline boxes.
void LayoutLineBox::CloseInlineBox(LayoutInlineBox* inline_box)
{
	ROCKET_ASSERT(open_inline_box == inline_box);

	open_inline_box = inline_box->GetParent();
	box_cursor += GetSpacing(inline_box->GetBox(), Box::RIGHT);
}
Exemplo n.º 3
0
void WebListBox::CalculateTextMetrics(WebGraphics * gc)
{
	static WebChar _a[] = {'A',0};
	WebFont font = mFont.GetFont();
	if (font)
	{
		miTextHeight = gc->TextHeight(_a, font);
		if (miTotalTextHeight < 0)
		{
			miTotalTextHeight = (miTextHeight + GetSpacing()) * miNumOptions;
		}
		if (miTotalTextWidth < 0)
		{
			miTotalTextWidth = 0;
			for (int t = 0; t < miNumOptions; t++)
			{
				if (mppOption[t])
				{
					DISPLAY_INT w = gc->TextWidth(mppOption[t], font);
					miTotalTextWidth = EBSMAX(w, GetTotalTextWidth());
				}
			}
		}
	}
}
Exemplo n.º 4
0
mitk::pa::Volume::Pointer mitk::pa::Volume::DeepCopy()
{
  long length = GetXDim()*GetYDim()*GetZDim();
  auto* data = new double[length];
  memcpy(data, GetData(), length * sizeof(double));

  return mitk::pa::Volume::New(data, GetXDim(), GetYDim(), GetZDim(), GetSpacing());
}
Exemplo n.º 5
0
// Appends an inline box to the end of the line box's list of inline boxes.
void LayoutLineBox::AppendBox(LayoutInlineBox* box)
{
	inline_boxes.push_back(box);

	box->SetParent(open_inline_box);
	box->SetLine(this);
	box->SetHorizontalPosition(LayoutEngine::Round(box_cursor + box->GetBox().GetEdge(Box::MARGIN, Box::LEFT)));
	box_cursor += GetSpacing(box->GetBox(), Box::LEFT);

	open_inline_box = box;
}
Exemplo n.º 6
0
void WebListBox::FitSelection(void)
{
	if (UseVScroll())
	{
		DISPLAY_INT offsetX, offsetY;
		WebRect r;

		GetScrollOffset(&offsetX, &offsetY);
		GetOptionsRect(&r);

		int pos = miSelected * (miTextHeight + GetSpacing());
		if (pos < offsetY)
		{
			mpVScroll->SetPosition(pos);
		}
		else if (pos > offsetY + r.Height() - miTextHeight - GetSpacing())
		{
			mpVScroll->SetPosition(pos - r.Height() + miTextHeight + GetSpacing());
		}
	}
}
Exemplo n.º 7
0
sf::Vector2f Box::CalculateRequisition() {
    sf::Vector2f requisition( 0.f, 0.f );
    unsigned int num_visible( 0 );
    ChildrenCont::const_iterator iter( m_children.begin() );
    ChildrenCont::const_iterator iterend( m_children.end() );

    for( ; iter != iterend; ++iter ) {
        if( !IsChildInteresting( iter->widget ) ) {
            continue;
        }

        ++num_visible;

        sf::Vector2f child_requisition( iter->widget->GetRequisition() );

        if( m_orientation == HORIZONTAL ) {
            requisition.x += child_requisition.x;
            requisition.y = std::max( requisition.y, child_requisition.y );
        }
        else {
            requisition.x = std::max( requisition.x, child_requisition.x );
            requisition.y += child_requisition.y;
        }
    }

    if( num_visible > 1 ) {
        if( m_orientation == HORIZONTAL ) {
            requisition.x += static_cast<float>( num_visible - 1 ) * GetSpacing();
        }
        else {
            requisition.y += static_cast<float>( num_visible - 1 ) * GetSpacing();
        }
    }

    float gap( Context::Get().GetEngine().GetProperty<float>( "Gap", shared_from_this() ) );
    requisition.x += 2 * gap;
    requisition.y += 2 * gap;

    return requisition;
}
Exemplo n.º 8
0
long WebListBox::OptionAt(DISPLAY_INT x, DISPLAY_INT y)
{
	DISPLAY_INT offsetX, offsetY;
	DISPLAY_INT offX = 0, offY = 0;

	if (mpParent)
	{
		mpParent->GetDisplayPosition(this, &offX, &offY);
	}

	WebRect box;
	GetOptionsRect(&box);
	y -= offY + box.top;
	GetScrollOffset(&offsetX, &offsetY);
	y += offsetY;
	return (y / (GetSpacing() + miTextHeight));
}
Exemplo n.º 9
0
// Attempts to add a new inline box to this line.
LayoutInlineBox* LayoutLineBox::AddBox(LayoutInlineBox* box)
{
	// Set to true if we're flowing the first box (with content) on the line.
	bool first_box = false;
	// The spacing this element must leave on the right of the line, to account not only for its margins and padding,
	// but also for its parents which will close immediately after it.
	float right_spacing;

	// If this line is unplaced, then this is the first inline box; if it is sized, then we can place and size this
	// line.
	if (!position_set)
	{
		// Add the new box to the list of boxes in the line box. As this line box has not been placed, we don't have to
		// check if it can fit yet.
		AppendBox(box);

		// If the new box has a physical prescence, then we must place this line once we've figured out how wide it has to
		// be.
		if (box->GetBox().GetSize().x >= 0)
		{
			// Calculate the dimensions for the box we need to fit.
			Vector2f minimum_dimensions = box->GetBox().GetSize();

			// Add the width of any empty, already closed tags, or still opened spaced tags.
			minimum_dimensions.x += box_cursor;

			// Calculate the right spacing for the element.
			right_spacing = GetSpacing(box->GetBox(), Box::RIGHT);
			// Add the right spacing for any ancestor elements that must close immediately after it.
			LayoutInlineBox* closing_box = box;
			while (closing_box != NULL &&
				   closing_box->IsLastChild())
			{
				closing_box = closing_box->GetParent();
				if (closing_box != NULL)
					right_spacing += GetSpacing(closing_box->GetBox(), Box::RIGHT);
			}

			if (!box->CanOverflow())
				minimum_dimensions.x += right_spacing;

			parent->PositionLineBox(position, dimensions.x, wrap_content, minimum_dimensions);
			dimensions.y = minimum_dimensions.y;

			first_box = true;
			position_set = true;
		}
		else
			return box;
	}

	// This line has already been placed and sized, so we'll check if we can fit this new inline box on the line.
	else
	{
		// Build up the spacing required on the right side of this element. This consists of the right spacing on the
		// new element, and the right spacing on all parent element that will close next.
		right_spacing = GetSpacing(box->GetBox(), Box::RIGHT);
		if (open_inline_box != NULL &&
			box->IsLastChild())
		{
			LayoutInlineBox* closing_box = open_inline_box;
			while (closing_box != NULL &&
				   closing_box->IsLastChild())
			{
				closing_box = closing_box->GetParent();
				if (closing_box != NULL)
					right_spacing += GetSpacing(closing_box->GetBox(), Box::RIGHT);
			}
		}

		// Determine the inline box's spacing requirements (before we get onto it's actual content width).
		float element_width = box->GetBox().GetPosition(Box::CONTENT).x;
		if (!box->CanOverflow())
			element_width += right_spacing;

		// Add on the box's content area (if it has content).
		if (box->GetBox().GetSize().x >= 0)
			element_width += box->GetBox().GetSize().x;

		if (wrap_content &&
			box_cursor + element_width > dimensions.x)
		{
			// We can't fit the new inline element into this box! So we'll close this line box, and send the inline box
			// onto the next line.
			return Close(box);
		}
		else
		{
			// We can fit the new inline element into this box.
			AppendBox(box);
		}
	}

	// Flow the box's content into the line.
	LayoutInlineBox* overflow_box = open_inline_box->FlowContent(first_box, wrap_content ? dimensions.x - (open_inline_box->GetPosition().x + open_inline_box->GetBox().GetPosition(Box::CONTENT).x) : -1, right_spacing);
	box_cursor += open_inline_box->GetBox().GetSize().x;

	// If our box overflowed, then we'll close this line (as no more content will fit onto it) and tell our block box
	// to make a new line.
	if (overflow_box != NULL)
	{
		open_inline_box = open_inline_box->GetParent();
		return Close(overflow_box);
	}

	return open_inline_box;
}
Exemplo n.º 10
0
std::vector<cleaver::AbstractScalarField*>
NRRDTools::segmentationToIndicatorFunctions(std::string filename, double sigma) {
  // read file using ITK
  if (filename.find(".nrrd") != std::string::npos) {
    itk::NrrdImageIOFactory::RegisterOneFactory();
  } else if (filename.find(".mha") != std::string::npos) {
    itk::MetaImageIOFactory::RegisterOneFactory();
  }
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName(filename);
  reader->Update();
  ImageType::Pointer image = reader->GetOutput();
  //determine the number of labels in the segmentations
  ImageCalculatorFilterType::Pointer imageCalculatorFilter
    = ImageCalculatorFilterType::New();
  imageCalculatorFilter->SetImage(reader->GetOutput());
  imageCalculatorFilter->Compute();
  auto maxLabel = static_cast<size_t>(imageCalculatorFilter->GetMaximum());
  auto minLabel = static_cast<size_t>(imageCalculatorFilter->GetMinimum());
  std::vector<cleaver::AbstractScalarField*> fields;
  //extract images from each label for an indicator function
  for (size_t i = minLabel, num = 0; i <= maxLabel; i++, num++) {
    //pull out this label
    ThreshType::Pointer thresh = ThreshType::New();
    thresh->SetInput(image);
    thresh->SetOutsideValue(0);
    thresh->ThresholdOutside(static_cast<double>(i) - 0.001,
      static_cast<double>(i) + 0.001);
    thresh->Update();
    //change the values to be from 0 to 1
    MultiplyImageFilterType::Pointer multiplyImageFilter =
      MultiplyImageFilterType::New();
    multiplyImageFilter->SetInput(thresh->GetOutput());
    multiplyImageFilter->SetConstant(1. / static_cast<double>(i));
    multiplyImageFilter->Update();
    //do some blurring
    GaussianBlurType::Pointer blur = GaussianBlurType::New();
    blur->SetInput(multiplyImageFilter->GetOutput());
    blur->SetVariance(sigma * sigma);
    blur->Update();
    //find the average value between
    ImageCalculatorFilterType::Pointer calc =
      ImageCalculatorFilterType::New();
    calc->SetImage(blur->GetOutput());
    calc->Compute();
    float mx = calc->GetMaximum();
    float mn = calc->GetMinimum();
    auto md = (mx + mn) / 2.f;
    //create a distance map with that minimum value as the levelset
    DMapType::Pointer dm = DMapType::New();
    dm->SetInput(blur->GetOutput());
    dm->SetInsideValue(md + 0.1f);
    dm->SetOutsideValue(md -0.1f);
    dm->Update();
    //MultiplyImageFilterType::Pointer mult =
    //  MultiplyImageFilterType::New();
    //mult->SetInput(blur->GetOutput());
    //mult->SetConstant(-20. / (mx - mn));
    //mult->Update();
    /*SubtractImageFilterType::Pointer subtractFilter
      = SubtractImageFilterType::New();
    subtractFilter->SetInput1(mult->GetOutput());
    subtractFilter->SetConstant2(1.);
    subtractFilter->Update();*/
    //convert the image to a cleaver "abstract field"
    auto img = dm->GetOutput();
    auto region = img->GetLargestPossibleRegion();
    auto numPixel = region.GetNumberOfPixels();
    float *data = new float[numPixel];
    auto x = region.GetSize()[0], y = region.GetSize()[1], z = region.GetSize()[2];
    fields.push_back(new cleaver::FloatField(data, x, y, z));
    auto beg = filename.find_last_of("/") + 1;
    auto name = filename.substr(beg, filename.size() - beg);
    auto fin = name.find_last_of(".");
    name = name.substr(0, fin);
    std::stringstream ss;
    ss << name << i;
    fields[num]->setName(ss.str());
    itk::ImageRegionConstIterator<ImageType> imageIterator(img, region);
    size_t pixel = 0;
    while (!imageIterator.IsAtEnd()) {
      // Get the value of the current pixel
      float val = static_cast<float>(imageIterator.Get());
      ((cleaver::FloatField*)fields[num])->data()[pixel++] = -val;
      ++imageIterator;
    }
    auto spacing = img->GetSpacing();
    ((cleaver::FloatField*)fields[num])->setScale(
      cleaver::vec3(spacing[0], spacing[1], spacing[2]));
    //NRRDTools::saveNRRDFile(fields[num], "a" + std::to_string(num));
  }
  return fields;
}
Exemplo n.º 11
0
  MITK_TEST_OUTPUT(<< "Calling SlicedGeometry3D::ChangeImageGeometryConsideringOriginOffset(true)");
  slicedGeometry->ChangeImageGeometryConsideringOriginOffset(true);
  MITK_TEST_OUTPUT(<< "SlicedGeometry3D is an image geometry");
  MITK_TEST_CONDITION_REQUIRED(slicedGeometry->GetImageGeometry() == true, "");
  MITK_TEST_OUTPUT(<< "First and last PlaneGeometry in SlicedGeometry3D are image geometries");
  MITK_TEST_CONDITION_REQUIRED(firstPlaneGeometry->GetImageGeometry() == true, "");
  MITK_TEST_CONDITION_REQUIRED(lastPlaneGeometry->GetImageGeometry() == true, "");

  MITK_TEST_OUTPUT(<< "Corner points of geometries didn't change");
  MITK_TEST_CONDITION_REQUIRED(slicedGeometry->GetCornerPoint(0) == firstCornerPointOfSlicedGeometry, "");
  MITK_TEST_CONDITION_REQUIRED(firstPlaneGeometry->GetCornerPoint(1) == secondCornerPointOfFirstPlaneGeometry, "");
  MITK_TEST_CONDITION_REQUIRED(lastPlaneGeometry->GetCornerPoint(2) == thirdCornerPointOfLastPlaneGeometry, "");

  MITK_TEST_OUTPUT(<< "Offsets were added to geometry origins");
  MITK_TEST_CONDITION_REQUIRED(slicedGeometry->GetOrigin() == originOfSlicedGeometry + slicedGeometry->GetSpacing() * 0.5, "");
  MITK_TEST_CONDITION_REQUIRED(firstPlaneGeometry->GetOrigin() == originOfFirstPlaneGeometry + firstPlaneGeometry->GetSpacing() * 0.5, "");
  MITK_TEST_CONDITION_REQUIRED(lastPlaneGeometry->GetOrigin() == originOfLastPlaneGeometry + lastPlaneGeometry->GetSpacing() * 0.5, "");

  MITK_TEST_OUTPUT(<< "Calling SlicedGeometry3D::ChangeImageGeometryConsideringOriginOffset(false)");
  slicedGeometry->ChangeImageGeometryConsideringOriginOffset(false);
  MITK_TEST_OUTPUT(<< "SlicedGeometry3D isn't an image geometry anymore");
  MITK_TEST_CONDITION_REQUIRED(slicedGeometry->GetImageGeometry() == false, "");
  MITK_TEST_OUTPUT(<< "First and last PlaneGeometry in SlicedGeometry3D are no image geometries anymore");
  MITK_TEST_CONDITION_REQUIRED(firstPlaneGeometry->GetImageGeometry() == false, "");
  MITK_TEST_CONDITION_REQUIRED(lastPlaneGeometry->GetImageGeometry() == false, "");

  MITK_TEST_OUTPUT(<< "Corner points of geometries didn't change");
  MITK_TEST_CONDITION_REQUIRED(slicedGeometry->GetCornerPoint(0) == firstCornerPointOfSlicedGeometry, "");
  MITK_TEST_CONDITION_REQUIRED(firstPlaneGeometry->GetCornerPoint(1) == secondCornerPointOfFirstPlaneGeometry, "");
  MITK_TEST_CONDITION_REQUIRED(lastPlaneGeometry->GetCornerPoint(2) == thirdCornerPointOfLastPlaneGeometry, "");
Exemplo n.º 12
0
void WebListBox::DrawThisOnly (DISPLAY_INT x, DISPLAY_INT y, WebGraphics *gc)
{
	WebRect visibleRegion, oldClip, frame(mRect);

	CalculateTextMetrics(gc);
	SetupScrollBars(gc);

	WebColor hilite, lolite, black, blue, white;
	hilite = white = gc->RGBToColor(0xff, 0xff, 0xff);
	lolite = black = gc->RGBToColor(0, 0, 0);
	blue = gc->RGBToColor(0, 0, 0xff);

	frame.MoveTo(x,y);

	if (mFlags & DISPLAY_FLAG_FOCUS && !(mStyle & LISTBOX_STYLE_NOFOCUSFRAME))
	{
		gc->Rectangle(&frame, black, black, WEBC_FALSE);
	}
	if (mStyle & LISTBOX_STYLE_NOT3D)
	{
		hilite = lolite = black;
	}

	frame.top += GetMargin();
	frame.left += GetMargin();
	frame.bottom -= GetMargin();
	frame.right -= GetMargin();

//	gc->StartBuffer();

	gc->Rectangle(&frame, GetBgColor(gc), GetBgColor(gc), WEBC_TRUE);
	DrawFrame(&frame, gc);

	DISPLAY_INT windowX, windowY;
	GetScrollOffset(&windowX, &windowY);
	long firstVisible = windowY / (miTextHeight + GetSpacing()) - 1;
	if (firstVisible < 0)
		firstVisible = 0;

	gc->GetClip(&oldClip);

	GetOptionsRect(&visibleRegion);
	visibleRegion.Shift(x,y);

	WebRect clip(visibleRegion);
	clip.And(&oldClip);
	gc->SetClip(&clip);

	WEBC_BOOL invert;
	int offset = firstVisible * (miTextHeight + GetSpacing());
	for (int t = firstVisible; t < miNumOptions; t++)
	{
		invert = ( ((t == GetSelected()) && !(mStyle & LISTBOX_STYLE_FOLLOW_MOUSE)) ||
		           ((t == miMouseOver)   &&  (mStyle & LISTBOX_STYLE_FOLLOW_MOUSE)) );

		if (invert)
		{
			PresetWebRect r (visibleRegion.left - windowX,  visibleRegion.top + offset - windowY,
			                 visibleRegion.right - windowX, visibleRegion.top + offset - windowY + miTextHeight - 1);
			gc->Rectangle(&r, GetSelectColor(gc), GetSelectColor(gc), WEBC_TRUE);
		}
		gc->Text(visibleRegion.left - windowX, visibleRegion.top + offset - windowY,
			 mppOption[t], (invert? GetBgColor(gc) : GetTextColor(gc)),
			 blue, WEBC_FALSE, mFont.GetFont());

		offset += miTextHeight + GetSpacing();
	}

	gc->SetClip(&oldClip);
//	gc->EndBuffer();
}
Exemplo n.º 13
0
void WebListBox::SetupScrollBars(WebGraphics * gc)
{
	WebRect window;
	GetContentRect(&window);
	DISPLAY_INT w = window.Width();
	DISPLAY_INT h = window.Height();

	WEBC_BOOL needH, needV;
	needH = needV = WEBC_FALSE;

	for (int t = 0; t < 2; t++)
	{
		if (w < GetTotalTextWidth())
		{
			needH = WEBC_TRUE;
			h -= miSliderWidth;
		}
		if (h < GetTotalTextHeight())
		{
			needV = WEBC_TRUE;
			w -= miSliderWidth;
		}
	}

	if (needH && !mpHScroll)
	{
		WEBC_NEW_VERBOSE(mpHScroll, WebHScroll,"wtlist:WebVscroll");
		if (mpHScroll)
		{
			mpHScroll->SetListener(this);
			mpHScroll->SetRange(GetTotalTextWidth());
			mpHScroll->SetStep(miTextHeight);
			mpHScroll->SetPosition(0);
			if (mFlags & DISPLAY_FLAG_DISABLED)
			{
				mpHScroll->Disable();
			}
			InsertLast(mpHScroll);
			ResizeScrollBars();
		}
	}
	else if (!needH && mpHScroll)
	{
		Remove(mpHScroll);
		WEBC_DELETE(mpHScroll);
		mpHScroll = WEBC_NULL;
	}

	if (needV && !mpVScroll)
	{
		WEBC_NEW_VERBOSE(mpVScroll, WebVScroll,"Wtlist:WebVscroll");
		if (mpVScroll)
		{
			mpVScroll->SetListener(this);
			mpVScroll->SetRange(GetTotalTextHeight());
			mpVScroll->SetStep(miTextHeight + GetSpacing());
			mpVScroll->SetPosition(0);
			if (mFlags & DISPLAY_FLAG_DISABLED)
			{
				mpVScroll->Disable();
			}
			InsertLast(mpVScroll);
			ResizeScrollBars();
		}
	}
	else if (!needV && mpVScroll)
	{
		Remove(mpVScroll);
		WEBC_DELETE(mpVScroll);
		mpVScroll = WEBC_NULL;
	}

}