Esempio n. 1
0
int main(void)
{														/*MAIN   */
int c=0;
int *arr;
int i=0;
int actSize;
int sizeArr = 100;
int amount=0;

	arr = (int*) malloc (sizeArr * sizeof(int));
	printf("Zadejte pocty sroubu pro jednotlive priruby:\n");
	while( c!='\n' && c != -1)  {
		if ( scanf("%d", &arr[i]) == 1) {
			if (arr[i]>=1)
			{
				if (++i == sizeArr) {
					sizeArr *= 2;
					if (!realloc (arr, sizeArr)) {
		//				printf	("Error during the realloc");
						free(arr);
						exit(1);
					}
				}
	   			c=getchar();
	//			printf("c: %d\n", c);	
				if (c != '\n' && c != ' ' && c != -1) {
				    free(arr);
					error();	
				}
			}
			else
			{
				free(arr);
				error();
			}
		}
		else {
			if (!feof(stdin))
			{
				free(arr);
				error();
			}
			break;
			/*printf("error: %d\n", feof(stdin));
			c = getchar();
			printf("c: %d\n", c);	
			while (c == ' ')
			{
				c = getchar();
				printf("c: %d\n", c);		
			}
			if (c != '\n' && c != -1)
			{
				free(arr);
				error();
			}*/
		}
//		printf("CCC: %d\n", c);
	}
	if(i<=1) {
		free(arr);		
		error();	
	}
	actSize = i;
/*	printf("act=%d\n",actSize);*/
	for(i=1;i<actSize-1;i++){      /*FINDING AN AMOUNT OF REMOVABLE ITEMS */
		amount+=arr[i];
	}
/*printf("total=%d\n",amount);*/
	
	if(actSize==2){
		onePart();
		free(arr);
	return 0;	
	}
	if (!recursion (arr, 0, actSize,0)) {
		printf ("Cena: %d\n", XMIN+amount);
	}
	free(arr);	
return 0;
}
Esempio n. 2
0
void QmitkSegmentationView::CreateNewSegmentation()
{
  mitk::DataNode::Pointer node = m_Controls->m_ManualToolSelectionBox->GetToolManager()->GetReferenceData(0);
  if (node.IsNotNull())
  {
    mitk::Image::Pointer image = dynamic_cast<mitk::Image*>( node->GetData() );
    if (image.IsNotNull())
    {
      if (image->GetDimension()>1)
      {
        // ask about the name and organ type of the new segmentation
        QmitkNewSegmentationDialog* dialog = new QmitkNewSegmentationDialog( m_Parent ); // needs a QWidget as parent, "this" is not QWidget

        QString storedList = QString::fromStdString( this->GetPreferences()->GetByteArray("Organ-Color-List","") );
        QStringList organColors;
        if (storedList.isEmpty())
        {
          organColors = GetDefaultOrganColorString();
        }
        else
        {
          /*
          a couple of examples of how organ names are stored:

          a simple item is built up like 'name#AABBCC' where #AABBCC is the hexadecimal notation of a color as known from HTML

          items are stored separated by ';'
          this makes it necessary to escape occurrences of ';' in name.
          otherwise the string "hugo;ypsilon#AABBCC;eugen#AABBCC" could not be parsed as two organs
          but we would get "hugo" and "ypsilon#AABBCC" and "eugen#AABBCC"

          so the organ name "hugo;ypsilon" is stored as "hugo\;ypsilon"
          and must be unescaped after loading

          the following lines could be one split with Perl's negative lookbehind
          */

          // recover string list from BlueBerry view's preferences
          QString storedString = QString::fromStdString( this->GetPreferences()->GetByteArray("Organ-Color-List","") );
          MITK_DEBUG << "storedString: " << storedString.toStdString();
          // match a string consisting of any number of repetitions of either "anything but ;" or "\;". This matches everything until the next unescaped ';'
          QRegExp onePart("(?:[^;]|\\\\;)*");
          MITK_DEBUG << "matching " << onePart.pattern().toStdString();
          int count = 0;
          int pos = 0;
          while( (pos = onePart.indexIn( storedString, pos )) != -1 )
          {
            ++count;
            int length = onePart.matchedLength();
            if (length == 0) break;
            QString matchedString = storedString.mid(pos, length);
            MITK_DEBUG << "   Captured length " << length << ": " << matchedString.toStdString();
            pos += length + 1; // skip separating ';'

            // unescape possible occurrences of '\;' in the string
            matchedString.replace("\\;", ";");

            // add matched string part to output list
            organColors << matchedString;
          }
          MITK_DEBUG << "Captured " << count << " organ name/colors";
        }

        dialog->SetSuggestionList( organColors );

        int dialogReturnValue = dialog->exec();

        if ( dialogReturnValue == QDialog::Rejected ) return; // user clicked cancel or pressed Esc or something similar

        // ask the user about an organ type and name, add this information to the image's (!) propertylist
        // create a new image of the same dimensions and smallest possible pixel type
        mitk::ToolManager* toolManager = m_Controls->m_ManualToolSelectionBox->GetToolManager();
        mitk::Tool* firstTool = toolManager->GetToolById(0);
        if (firstTool)
        {
          try
          {
            mitk::DataNode::Pointer emptySegmentation =
              firstTool->CreateEmptySegmentationNode( image, dialog->GetSegmentationName().toStdString(), dialog->GetColor() );

            //Here we change the reslice interpolation mode for a segmentation, so that contours in rotated slice can be shown correctly
            emptySegmentation->SetProperty( "reslice interpolation", mitk::VtkResliceInterpolationProperty::New(VTK_RESLICE_NEAREST) );
            // initialize showVolume to false to prevent recalculating the volume while working on the segmentation
            emptySegmentation->SetProperty( "showVolume", mitk::BoolProperty::New( false ) );

            if (!emptySegmentation) return; // could be aborted by user

            UpdateOrganList( organColors, dialog->GetSegmentationName(), dialog->GetColor() );

            /*
            escape ';' here (replace by '\;'), see longer comment above
            */
            std::string stringForStorage = organColors.replaceInStrings(";","\\;").join(";").toStdString();
            MITK_DEBUG << "Will store: " << stringForStorage;
            this->GetPreferences()->PutByteArray("Organ-Color-List", stringForStorage );
            this->GetPreferences()->Flush();

            if(m_Controls->m_ManualToolSelectionBox->GetToolManager()->GetWorkingData(0))
            {
              m_Controls->m_ManualToolSelectionBox->GetToolManager()->GetWorkingData(0)->SetSelected(false);
            }
            emptySegmentation->SetSelected(true);
            this->GetDefaultDataStorage()->Add( emptySegmentation, node ); // add as a child, because the segmentation "derives" from the original

            this->FireNodeSelected( emptySegmentation );
            this->OnSelectionChanged( emptySegmentation );
            this->SetToolManagerSelection(node, emptySegmentation);
          }
          catch (std::bad_alloc)
          {
            QMessageBox::warning(NULL,"Create new segmentation","Could not allocate memory for new segmentation");
          }
        }
      }
      else
      {
        QMessageBox::information(NULL,"Segmentation","Segmentation is currently not supported for 2D images");
      }
    }
  }
  else
  {
    MITK_ERROR << "'Create new segmentation' button should never be clickable unless a patient image is selected...";
  }
}