Пример #1
0
static HRESULT OnAddNewSetting(PWLAN_INFO psInfo)
{
    HRESULT        hr      = S_OK;
    WLAN_CFG_PROPS sProps  = {0};
    LPTSTR         pszSSID = NULL;

    // Init    
    sProps.dwFlags = WZCDLG_PROPS_RWSSID | WZCDLG_PROPS_RWINFR;
    sProps.dwMask = SHWZCF_SETMASK_ALL;
    SHWZCCreateDefaultNetwork(&sProps.wzcnet);

    // Save the dialog info so we can check for duplicate names
    sProps.psWLanInfo = psInfo;

    hr = WZCCreateNetworkWLanPropsDlgs(psInfo->hDlg, &sProps);
    CHR(hr);

    if (IDOK == sProps.nReturn)
    {
        hr = ApplyProperties(psInfo, &sProps);
        CHR(hr);
    }

Error:
    LocalFree(sProps.pvEapData);
    return hr;
}
void mitk::EnhancedPointSetVtkMapper3D::GenerateDataForRenderer( mitk::BaseRenderer * renderer )
{

  BaseLocalStorage *ls = m_LSH.GetLocalStorage(renderer);
  bool needGenerateData = ls->IsGenerateDataRequired( renderer, this, GetDataNode() );

  if(needGenerateData)
  {
    ls->UpdateGenerateDataTime();
    this->UpdateVtkObjects();
  }

  ApplyProperties(renderer);
}
Пример #3
0
//==========================================================================*
// Function: OnNetworkProperties
//
// Purpose:  (1) Display the network properties dialog
//           (2) Move(insert) the network to the head of the prefered list
//           
// Arguments: 
//     [IN] psInfo - pointer to the WLAN_INFO structure
//     [IN] item   - item need to show context menu
//
// Return Values:
//     BOOL - TRUE for handle it successfully
//==========================================================================*
static BOOL OnNetworkProperties(PWLAN_INFO psInfo, INT iItem)
{
    HRESULT        hr = S_OK;
    WLAN_CFG_PROPS sProps = {0};
    PCSHWZCNET     pwzcnet = (PCSHWZCNET)GetListItemLPARAM(psInfo->hwndNetList, iItem);
    BOOL           fAdhoc;
    TCHAR          szGUID[MAX_PATH];
    FINDGUID       fg;

    CBR(iItem > 0 && pwzcnet != NULL);

    // If the selected network is a "Permanent" non-editable network, exit without 
    // showing the NetworkProperties pages
    fAdhoc = BOOLIFY(SHWZCF_NET_ADHOC & pwzcnet->dwFlags);
    CBREx (!SHWZCIsPermanentNetwork(pwzcnet->szName, fAdhoc), S_FALSE);

    // Get the current EAP data
    hr = SHWZCGetNetwork(psInfo->hshwzc, pwzcnet->szName, fAdhoc,
        &sProps.wzcnet, &sProps.pvEapData, &sProps.cbEapData);
    CHR(hr);

    // We don't care about the result, since if this fails we just won't match
    // with any networks and we'll use the default
    szGUID[0] = 0;
    SHWZCGetDestinationGUID(psInfo->hshwzc, pwzcnet->szName, fAdhoc,
        szGUID, ARRAYSIZE(szGUID));

    fg.pszGUID = szGUID;
    fg.uIndex = 0;
    if (S_FALSE == SHWZCEnumDestinations(EnumFindGUID, &fg))
    {
        sProps.uMeta = fg.uIndex;
    }

    sProps.psWLanInfo = psInfo;
    
    hr = WZCCreateNetworkWLanPropsDlgs(psInfo->hDlg, &sProps);
    CHR(hr);

    if (IDOK == sProps.nReturn)
    {
        hr = ApplyProperties(psInfo, &sProps);
        CHR(hr); 
    }

Error:
    LocalFree(sProps.pvEapData);
    return SUCCEEDED(hr);
}
Пример #4
0
void mitk::SurfaceVtkMapper3D::GenerateDataForRenderer(mitk::BaseRenderer* renderer)
{
  LocalStorage *ls = m_LSH.GetLocalStorage(renderer);
  
  bool visible = IsVisible(renderer);

  if(visible==false)
  {
    ls->m_Actor->VisibilityOff();
    return;
  }

  //
  // set the input-object at time t for the mapper
  //
  mitk::Surface::Pointer input  = const_cast< mitk::Surface* >( this->GetInput() );
  vtkPolyData * polydata = input->GetVtkPolyData( this->GetTimestep() );
  if(polydata == NULL) 
  {
    ls->m_Actor->VisibilityOff();
    return;
  }

  if ( m_GenerateNormals )
  {
    ls->m_VtkPolyDataNormals->SetInput( polydata );
    ls->m_VtkPolyDataMapper->SetInput( ls->m_VtkPolyDataNormals->GetOutput() );
  }
  else
  {
    ls->m_VtkPolyDataMapper->SetInput( polydata );
  }

  //
  // apply properties read from the PropertyList
  //
  ApplyProperties(ls->m_Actor, renderer);

  if(visible)
    ls->m_Actor->VisibilityOn();
}
void mitk::UnstructuredGridVtkMapper3D::GenerateDataForRenderer(mitk::BaseRenderer* renderer)
{

  mitk::DataNode::ConstPointer node = this->GetDataNode();

  BaseLocalStorage *ls = m_LSH.GetLocalStorage(renderer);
  bool needGenerateData = ls->IsGenerateDataRequired( renderer, this, GetDataNode() );

  if(needGenerateData)
  {
    ls->UpdateGenerateDataTime();

    m_Assembly->VisibilityOn();

    m_ActorWireframe->GetProperty()->SetAmbient(1.0);
    m_ActorWireframe->GetProperty()->SetDiffuse(0.0);
    m_ActorWireframe->GetProperty()->SetSpecular(0.0);

    mitk::TransferFunctionProperty::Pointer transferFuncProp;
    if (node->GetProperty(transferFuncProp, "TransferFunction"))
    {
      mitk::TransferFunction::Pointer transferFunction = transferFuncProp->GetValue();
      if (transferFunction->GetColorTransferFunction()->GetSize() < 2)
      {
        mitk::UnstructuredGrid::Pointer input  = const_cast< mitk::UnstructuredGrid* >(this->GetInput());
        if (input.IsNull()) return;

        vtkUnstructuredGrid * grid = input->GetVtkUnstructuredGrid(this->GetTimestep());
        if (grid == 0) return;

        double* scalarRange = grid->GetScalarRange();
        vtkColorTransferFunction* colorFunc = transferFunction->GetColorTransferFunction();
        colorFunc->RemoveAllPoints();
        colorFunc->AddRGBPoint(scalarRange[0], 1, 0, 0);
        colorFunc->AddRGBPoint((scalarRange[0] + scalarRange[1])/2.0, 0, 1, 0);
        colorFunc->AddRGBPoint(scalarRange[1], 0, 0, 1);
      }
    }
  }

  bool visible = true;
  GetDataNode()->GetVisibility(visible, renderer, "visible");

  if(!visible)
  {
    m_Assembly->VisibilityOff();
    return;
  }

  //
  // get the TimeGeometry of the input object
  //
  mitk::UnstructuredGrid::Pointer input  = const_cast< mitk::UnstructuredGrid* >( this->GetInput() );

  //
  // set the input-object at time t for the mapper
  //
  vtkUnstructuredGrid * grid = input->GetVtkUnstructuredGrid( this->GetTimestep() );
  if(grid == 0)
  {
    m_Assembly->VisibilityOff();
    return;
  }

  m_Assembly->VisibilityOn();

  m_VtkTriangleFilter->SetInputData(grid);
  m_VtkDataSetMapper->SetInput(grid);
  m_VtkDataSetMapper2->SetInput(grid);

  bool clip = false;
  node->GetBoolProperty("enable clipping", clip);
  mitk::DataNode::Pointer bbNode = renderer->GetDataStorage()->GetNamedDerivedNode("Clipping Bounding Object", node);
  if (clip && bbNode.IsNotNull())
  {
    m_VtkDataSetMapper->SetBoundingObject(dynamic_cast<mitk::BoundingObject*>(bbNode->GetData()));
    m_VtkDataSetMapper2->SetBoundingObject(dynamic_cast<mitk::BoundingObject*>(bbNode->GetData()));
  }
  else
  {
    m_VtkDataSetMapper->SetBoundingObject(0);
    m_VtkDataSetMapper2->SetBoundingObject(0);
  }

  //
  // apply properties read from the PropertyList
  //
  ApplyProperties(0, renderer);
}
void mitk::UnstructuredGridMapper2D::Paint( mitk::BaseRenderer* renderer )
{
  if ( IsVisible( renderer ) == false )
    return ;

  vtkLinearTransform * vtktransform = GetDataNode()->GetVtkTransform();
  vtkLinearTransform * inversetransform = vtktransform->GetLinearInverse();

  Geometry2D::ConstPointer worldGeometry = renderer->GetCurrentWorldGeometry2D();
  PlaneGeometry::ConstPointer worldPlaneGeometry = dynamic_cast<const PlaneGeometry*>( worldGeometry.GetPointer() );

  Point3D point;
  Vector3D normal;

  if(worldPlaneGeometry.IsNotNull())
  {
    // set up vtkPlane according to worldGeometry
    point=worldPlaneGeometry->GetOrigin();
    normal=worldPlaneGeometry->GetNormal(); normal.Normalize();
    m_Plane->SetTransform((vtkAbstractTransform*)NULL);
  }
  else
  {
    //@FIXME: does not work correctly. Does m_Plane->SetTransform really transforms a "plane plane" into a "curved plane"?
    return;
    AbstractTransformGeometry::ConstPointer worldAbstractGeometry = dynamic_cast<const AbstractTransformGeometry*>(renderer->GetCurrentWorldGeometry2D());
    if(worldAbstractGeometry.IsNotNull())
    {
      // set up vtkPlane according to worldGeometry
      point=const_cast<mitk::BoundingBox*>(worldAbstractGeometry->GetParametricBoundingBox())->GetMinimum();
      FillVector3D(normal, 0, 0, 1);
      m_Plane->SetTransform(worldAbstractGeometry->GetVtkAbstractTransform()->GetInverse());
    }
    else
      return;
  }

  vtkFloatingPointType vp[ 3 ], vnormal[ 3 ];

  vnl2vtk(point.Get_vnl_vector(), vp);
  vnl2vtk(normal.Get_vnl_vector(), vnormal);

  //normally, we would need to transform the surface and cut the transformed surface with the cutter.
  //This might be quite slow. Thus, the idea is, to perform an inverse transform of the plane instead.
  //@todo It probably does not work for scaling operations yet:scaling operations have to be
  //dealed with after the cut is performed by scaling the contour.
  inversetransform->TransformPoint( vp, vp );
  inversetransform->TransformNormalAtPoint( vp, vnormal, vnormal );

  m_Plane->SetOrigin( vp );
  m_Plane->SetNormal( vnormal );

  // set data into cutter
  m_Slicer->SetInput( m_VtkPointSet );
  //    m_Cutter->GenerateCutScalarsOff();
  //    m_Cutter->SetSortByToSortByCell();

  // calculate the cut
  m_Slicer->Update();

  // fetch geometry
  mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry();
  assert( displayGeometry );
  //  float toGL=displayGeometry->GetSizeInDisplayUnits()[1];

  //apply color and opacity read from the PropertyList
  ApplyProperties( renderer );

  // traverse the cut contour
  vtkPolyData * contour = m_Slicer->GetOutput();

  vtkPoints *vpoints = contour->GetPoints();
  vtkCellArray *vlines = contour->GetLines();
  vtkCellArray *vpolys = contour->GetPolys();
  vtkPointData *vpointdata = contour->GetPointData();
  vtkDataArray* vscalars = vpointdata->GetScalars();

  vtkCellData *vcelldata = contour->GetCellData();
  vtkDataArray* vcellscalars = vcelldata->GetScalars();

  const int numberOfLines = contour->GetNumberOfLines();
  const int numberOfPolys = contour->GetNumberOfPolys();

  const bool useCellData = m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_DEFAULT ||
              m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_CELL_DATA;
  const bool usePointData = m_ScalarMode->GetVtkScalarMode() == VTK_SCALAR_MODE_USE_POINT_DATA;

  Point3D p;
  Point2D p2d;

  vlines->InitTraversal();
  vpolys->InitTraversal();
  
  mitk::Color outlineColor = m_Color->GetColor();

  glLineWidth((float)m_LineWidth->GetValue());

  for (int i = 0;i < numberOfLines;++i )
  {
    vtkIdType *cell(0);
    vtkIdType cellSize(0);

    vlines->GetNextCell( cellSize, cell );

    float rgba[4] = {outlineColor[0], outlineColor[1], outlineColor[2], 1.0f};
    if (m_ScalarVisibility->GetValue() && vcellscalars)
    {
      if ( useCellData )
      {  // color each cell according to cell data
        double scalar = vcellscalars->GetComponent( i, 0 );
        double rgb[3] = { 1.0f, 1.0f, 1.0f };
        m_ScalarsToColors->GetColor(scalar, rgb);
        rgba[0] = (float)rgb[0];
        rgba[1] = (float)rgb[1];
        rgba[2] = (float)rgb[2];
        rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
      }
      else if ( usePointData )
      {
        double scalar = vscalars->GetComponent( i, 0 );
        double rgb[3] = { 1.0f, 1.0f, 1.0f };
        m_ScalarsToColors->GetColor(scalar, rgb);
        rgba[0] = (float)rgb[0];
        rgba[1] = (float)rgb[1];
        rgba[2] = (float)rgb[2];
        rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
      }
    }
    
    glColor4fv( rgba );
    
    glBegin ( GL_LINE_LOOP );
    for ( int j = 0;j < cellSize;++j )
    {
      vpoints->GetPoint( cell[ j ], vp );
      //take transformation via vtktransform into account
      vtktransform->TransformPoint( vp, vp );

      vtk2itk( vp, p );

      //convert 3D point (in mm) to 2D point on slice (also in mm)
      worldGeometry->Map( p, p2d );

      //convert point (until now mm and in worldcoordinates) to display coordinates (units )
      displayGeometry->WorldToDisplay( p2d, p2d );

      //convert display coordinates ( (0,0) is top-left ) in GL coordinates ( (0,0) is bottom-left )
      //p2d[1]=toGL-p2d[1];

      //add the current vertex to the line
      glVertex2f( p2d[0], p2d[1] );
    }
    glEnd ();

  }
  
  bool polyOutline = m_Outline->GetValue();
  bool scalarVisibility = m_ScalarVisibility->GetValue();

  // only draw polygons if there are cell scalars
  // or the outline property is set to true
  if ((scalarVisibility && vcellscalars) || polyOutline)
  {
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    // cache the transformed points
    // a fixed size array is way faster than 'new'
    // slices through 3d cells usually do not generated
    // polygons with more than 6 vertices
    Point2D cachedPoints[10];

    for (int i = 0;i < numberOfPolys;++i )
    {
      vtkIdType *cell(0);
      vtkIdType cellSize(0);

      vpolys->GetNextCell( cellSize, cell );

      float rgba[4] = {1.0f, 1.0f, 1.0f, 0};
      if (scalarVisibility && vcellscalars)
      {
        if ( useCellData )
        {  // color each cell according to cell data
          double scalar = vcellscalars->GetComponent( i, 0 );
          double rgb[3] = { 1.0f, 1.0f, 1.0f };
          m_ScalarsToColors->GetColor(scalar, rgb);
          rgba[0] = (float)rgb[0];
          rgba[1] = (float)rgb[1];
          rgba[2] = (float)rgb[2];
          rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
        }
        else if ( usePointData )
        {
          double scalar = vscalars->GetComponent( i, 0 );
          double rgb[3] = { 1.0f, 1.0f, 1.0f };
          m_ScalarsToColors->GetColor(scalar, rgb);
          rgba[0] = (float)rgb[0];
          rgba[1] = (float)rgb[1];
          rgba[2] = (float)rgb[2];
          rgba[3] = (float)m_ScalarsToOpacity->GetValue(scalar);
        }
      }
      glColor4fv( rgba );

      glBegin( GL_POLYGON );
      for (int j = 0; j < cellSize; ++j)
      {
        vpoints->GetPoint( cell[ j ], vp );
        //take transformation via vtktransform into account
        vtktransform->TransformPoint( vp, vp );

        vtk2itk( vp, p );

        //convert 3D point (in mm) to 2D point on slice (also in mm)
        worldGeometry->Map( p, p2d );

        //convert point (until now mm and in worldcoordinates) to display coordinates (units )
        displayGeometry->WorldToDisplay( p2d, p2d );

        //convert display coordinates ( (0,0) is top-left ) in GL coordinates ( (0,0) is bottom-left )
        //p2d[1]=toGL-p2d[1];

        cachedPoints[j][0] = p2d[0];
        cachedPoints[j][1] = p2d[1];

        //add the current vertex to the line
        glVertex2f( p2d[0], p2d[1] );
      }
      glEnd();

      if (polyOutline)
      {
        glColor4f(outlineColor[0], outlineColor[1], outlineColor[2], 1.0f);

        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
        glBegin( GL_POLYGON );
        //glPolygonOffset(1.0, 1.0);
        for (int j = 0; j < cellSize; ++j)
        {
          //add the current vertex to the line
          glVertex2f( cachedPoints[j][0], cachedPoints[j][1] );
        }
        glEnd();
      }
    }
    glDisable(GL_BLEND);
  }
}
Пример #7
0
void mitk::ContourMapper2D::Paint(mitk::BaseRenderer * renderer)
  {
  if(IsVisible(renderer)==false) return;

  ////  @FIXME: Logik fuer update
  bool updateNeccesary=true;

  if (updateNeccesary) 
    {
    mitk::Contour::Pointer input =  const_cast<mitk::Contour*>(this->GetInput());

    // ok, das ist aus GenerateData kopiert
    mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry();
    assert(displayGeometry.IsNotNull());

    //apply color and opacity read from the PropertyList
    ApplyProperties(renderer);

    vtkLinearTransform* transform = GetDataNode()->GetVtkTransform();

    //    Contour::OutputType point;
    Contour::BoundingBoxType::PointType point;

    mitk::Point3D p, projected_p;
    float vtkp[3];
    float lineWidth = 3.0;

    if (dynamic_cast<mitk::FloatProperty *>(this->GetDataNode()->GetProperty("Width")) != NULL)
      lineWidth = dynamic_cast<mitk::FloatProperty*>(this->GetDataNode()->GetProperty("Width"))->GetValue();
    glLineWidth(lineWidth);

    if (input->GetClosed())
      {
      glBegin (GL_LINE_LOOP);
      }
    else 
      {
      glBegin (GL_LINE_STRIP);
      }

    //Contour::InputType end = input->GetContourPath()->EndOfInput();
    //if (end > 50000) end = 0;

    mitk::Contour::PointsContainerPointer points = input->GetPoints();
    mitk::Contour::PointsContainerIterator pointsIt = points->Begin();



    while ( pointsIt != points->End() )
      {
      //while ( idx != end )
      //{
      //      point = input->GetContourPath()->Evaluate(idx);
      point = pointsIt.Value();

      itk2vtk(point, vtkp);
      transform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp,p);

      displayGeometry->Project(p, projected_p);
      bool projectmode=false;
      GetDataNode()->GetVisibility(projectmode, renderer, "project");
      bool drawit=false;
      if(projectmode)
        drawit=true;
      else
      {
        Vector3D diff=p-projected_p;
        if(diff.GetSquaredNorm()<1.0)
          drawit=true;
      }
      if(drawit)
      {
        Point2D pt2d, tmp;
        displayGeometry->Map(projected_p, pt2d);
        displayGeometry->WorldToDisplay(pt2d, pt2d);
        glVertex2f(pt2d[0], pt2d[1]);
      }

      pointsIt++;
      //      idx += 1;
      }
    glEnd ();

    glLineWidth(1.0);

    }
  }
Пример #8
0
fsInternetResult fsInternetUploader::OpenUrl()
{
	fsInternetResult ir;
	fsUpload_NetworkProperties* dnp = &m_unp;

	BOOL bOpenAnotherReq = m_pInetFile != NULL;

	if (bOpenAnotherReq == FALSE)
	{
		m_pInetFile = new fsInternetURLFile;
		m_pInetFile->SetDialogFunc (_InetFileDialogFunc, this, 0);
	
		vmsInternetSession* pSession = new vmsInternetSession;
		char szProxy [10000];
		vmsMakeWinInetProxy (dnp->pszProxyName, dnp->enProtocol, dnp->enProtocol, szProxy);
		ir  = pSession->Create (dnp->pszAgent, dnp->enAccType, szProxy, dnp->enProtocol);
		if (ir != IR_SUCCESS)
		{
			delete pSession;
			SAFE_DELETE (m_pInetFile);
			return ir;
		}
	
		ApplyProxySettings (pSession, dnp);
	
		m_pInetFile->Initialize (pSession, TRUE);

		ApplyProperties (m_pInetFile, dnp);

		
		if (dnp->enProtocol == NP_FTP && dnp->enFtpTransferType == FTT_UNKNOWN)
		{
			int posPath = strlen (dnp->pszPathName) - 1;
			int posExt = 0;
			LPSTR pszExt = new char [MAX_PATH];

			while (posPath && dnp->pszPathName [posPath] != '.')
				pszExt [posExt++] = dnp->pszPathName [posPath--];

			if (posPath)
			{
				LPSTR pszExtension = new char [MAX_PATH];

				pszExt [posExt] = 0;

				int i = 0;
				for (i = 0; i < posExt; i++)
					pszExtension [i] = pszExt [posExt - i - 1];

				pszExtension [i] = 0;
			
				if (IsExtInExtsStr (_pDllCaller->GetSettings ()->FtpAsciiExts (), pszExtension))
					m_pInetFile->FtpSetTransferType (FTT_ASCII);
				else
					m_pInetFile->FtpSetTransferType (FTT_BINARY);

				delete [] pszExtension;
			}
			else 
			{
				m_pInetFile->FtpSetTransferType (FTT_BINARY);
			}

			delete [] pszExt;
		}
	}

	
	
	m_uPosition -= m_uPosition % m_dwUploadPartSize;

	if (bOpenAnotherReq)
	{
		ir = m_pInetFile->OpenAnotherRequestOnServer (dnp->pszPathName, m_uPosition,
			min (m_dwUploadPartSize, m_uFileSize - m_uPosition), m_uFileSize);
	}
	else
	{
		ir = m_pInetFile->OpenEx (fsNPToScheme (dnp->enProtocol), dnp->pszServerName,
					dnp->pszUserName, dnp->pszPassword, dnp->uServerPort, 
					dnp->pszPathName, m_uPosition, FALSE, 
					min (m_dwUploadPartSize, m_uFileSize - m_uPosition), m_uFileSize);
	}

	if (m_bNeedStop)
	{
		SAFE_DELETE (m_pInetFile);
		return IR_S_FALSE;
	}

	if (ir != IR_SUCCESS)
	{
		
		SAFE_DELETE (m_pInetFile);
		return ir;
	}
	
	return IR_SUCCESS;
}
Пример #9
0
void mitk::MeshMapper2D::Paint( mitk::BaseRenderer *renderer )
{
  if ( !this->IsVisible(renderer) ) return;

  //  @FIXME: Logik fuer update
  bool updateNeccesary = true;

  if (updateNeccesary)
  {
  //aus GenerateData
    mitk::Mesh::Pointer input = const_cast<mitk::Mesh*>(this->GetInput());

    // Get the TimeSlicedGeometry of the input object
    const TimeSlicedGeometry* inputTimeGeometry = input->GetTimeSlicedGeometry();
    if (( inputTimeGeometry == NULL ) || ( inputTimeGeometry->GetTimeSteps() == 0 ) )
    {
      return;
    }

    //
    // get the world time
    //
    const Geometry2D* worldGeometry = renderer->GetCurrentWorldGeometry2D();
    assert( worldGeometry != NULL );
    ScalarType time = worldGeometry->GetTimeBounds()[ 0 ];

    //
    // convert the world time in time steps of the input object
    //
    int timeStep=0;
    if ( time > ScalarTypeNumericTraits::NonpositiveMin() )
      timeStep = inputTimeGeometry->MSToTimeStep( time );
    if ( inputTimeGeometry->IsValidTime( timeStep ) == false )
    {
      return;
    }


    mitk::Mesh::MeshType::Pointer itkMesh = input->GetMesh( timeStep );

    if ( itkMesh.GetPointer() == NULL)
    {
      return;
    }


    mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry();
    assert(displayGeometry.IsNotNull());

    const PlaneGeometry* worldplanegeometry = dynamic_cast<const PlaneGeometry*>(renderer->GetCurrentWorldGeometry2D());

    //apply color and opacity read from the PropertyList
    ApplyProperties(renderer);

    vtkLinearTransform* transform = GetDataNode()->GetVtkTransform();

    //List of the Points
    Mesh::DataType::PointsContainerConstIterator it, end;
    it=itkMesh->GetPoints()->Begin();
    end=itkMesh ->GetPoints()->End();

    //iterator on the additional data of each point
    Mesh::PointDataIterator dataIt;//, dataEnd;
    dataIt=itkMesh->GetPointData()->Begin();

    //for switching back to old color after using selected color
    float unselectedColor[4];
    glGetFloatv(GL_CURRENT_COLOR,unselectedColor);

    while(it!=end)
    {
      mitk::Point3D p, projected_p;
      float vtkp[3];

      itk2vtk(it->Value(), vtkp);
      transform->TransformPoint(vtkp, vtkp);
      vtk2itk(vtkp,p);

      displayGeometry->Project(p, projected_p);
      Vector3D diff=p-projected_p;
      if(diff.GetSquaredNorm()<4.0)
      {
        Point2D pt2d, tmp;
        displayGeometry->Map(projected_p, pt2d);
        displayGeometry->WorldToDisplay(pt2d, pt2d);

        Vector2D horz,vert;
        horz[0]=5; horz[1]=0;
        vert[0]=0; vert[1]=5;

        //check if the point is to be marked as selected
        if (dataIt->Value().selected)
        {
          horz[0]=8;
          vert[1]=8;
          glColor3f(selectedColor[0],selectedColor[1],selectedColor[2]);//red

          switch (dataIt->Value().pointSpec)
          {
          case PTSTART:
            {
              //a quad
              glBegin (GL_LINE_LOOP);
                tmp=pt2d-horz+vert;      glVertex2fv(&tmp[0]);
                tmp=pt2d+horz+vert;      glVertex2fv(&tmp[0]);
                tmp=pt2d+horz-vert;      glVertex2fv(&tmp[0]);
                tmp=pt2d-horz-vert;      glVertex2fv(&tmp[0]);
              glEnd ();
            }
            break;
          case PTUNDEFINED:
            {
              //a diamond around the point
              glBegin (GL_LINE_LOOP);
                tmp=pt2d-horz;      glVertex2fv(&tmp[0]);
                tmp=pt2d+vert;      glVertex2fv(&tmp[0]);
                tmp=pt2d+horz;      glVertex2fv(&tmp[0]);
                tmp=pt2d-vert;      glVertex2fv(&tmp[0]);
              glEnd ();
            }
            break;
          default:
            break;
          }//switch

          //the actual point
          glBegin (GL_POINTS);
            tmp=pt2d;             glVertex2fv(&tmp[0]);
          glEnd ();
        }
        else //if not selected
        {
          glColor3f(unselectedColor[0],unselectedColor[1],unselectedColor[2]);
          switch (dataIt->Value().pointSpec)
          {
          case PTSTART:
            {
              //a quad
              glBegin (GL_LINE_LOOP);
                tmp=pt2d-horz+vert;      glVertex2fv(&tmp[0]);
                tmp=pt2d+horz+vert;      glVertex2fv(&tmp[0]);
                tmp=pt2d+horz-vert;      glVertex2fv(&tmp[0]);
                tmp=pt2d-horz-vert;      glVertex2fv(&tmp[0]);
              glEnd ();
            }
          case PTUNDEFINED:
            {
              //drawing crosses
              glBegin (GL_LINES);
                  tmp=pt2d-horz;      glVertex2fv(&tmp[0]);
                  tmp=pt2d+horz;      glVertex2fv(&tmp[0]);
                  tmp=pt2d-vert;      glVertex2fv(&tmp[0]);
                  tmp=pt2d+vert;      glVertex2fv(&tmp[0]);
              glEnd ();
            }
    default:
            {
        break;
            }
          }//switch
        }//else
      }
      ++it;
      ++dataIt;
    }

    //now connect the lines inbetween
    mitk::Mesh::PointType thisPoint; thisPoint.Fill(0);
    Point2D *firstOfCell = NULL;
    Point2D *lastPoint = NULL;
    unsigned int lastPointId = 0;
    bool lineSelected = false;

    Point3D firstOfCell3D;
    Point3D lastPoint3D;
    bool first;
    mitk::Line<mitk::ScalarType> line;
    std::vector<mitk::Point3D> intersectionPoints;
    double t;

    //iterate through all cells and then iterate through all indexes of points in that cell
    Mesh::CellIterator cellIt, cellEnd;
    Mesh::CellDataIterator cellDataIt;//, cellDataEnd;
    Mesh::PointIdIterator cellIdIt, cellIdEnd;

    cellIt = itkMesh->GetCells()->Begin();
    cellEnd = itkMesh->GetCells()->End();
    cellDataIt = itkMesh->GetCellData()->Begin();

    while (cellIt != cellEnd)
    {
      unsigned int numOfPointsInCell = cellIt->Value()->GetNumberOfPoints();
      if (numOfPointsInCell>1)
      {
        //iterate through all id's in the cell
        cellIdIt = cellIt->Value()->PointIdsBegin();
        cellIdEnd = cellIt->Value()->PointIdsEnd();

        firstOfCell3D = input->GetPoint(*cellIdIt);

        intersectionPoints.clear();
        intersectionPoints.reserve(numOfPointsInCell);

        first = true;

        while(cellIdIt != cellIdEnd)
        {
          lastPoint3D = thisPoint;

          thisPoint = input->GetPoint(*cellIdIt);

          //search in data (vector<> selectedLines) if the index of the point is set. if so, then the line is selected.
          lineSelected = false;
          Mesh::SelectedLinesType selectedLines = cellDataIt->Value().selectedLines;

          //a line between 1(lastPoint) and 2(pt2d) has the Id 1, so look for the Id of lastPoint
          //since we only start, if we have more than one point in the cell, lastPointId is initiated with 0
          Mesh::SelectedLinesIter position = std::find(selectedLines.begin(), selectedLines.end(), lastPointId);
          if (position != selectedLines.end())
          {
            lineSelected = true;
          }

          mitk::Point3D p, projected_p;
          float vtkp[3];
          itk2vtk(thisPoint, vtkp);
          transform->TransformPoint(vtkp, vtkp);
          vtk2itk(vtkp,p);
          displayGeometry->Project(p, projected_p);
          Vector3D diff=p-projected_p;
          if(diff.GetSquaredNorm()<4.0)
          {
            Point2D pt2d, tmp;
            displayGeometry->Map(projected_p, pt2d);
            displayGeometry->WorldToDisplay(pt2d, pt2d);

            if (lastPoint == NULL)
            {
              //set the first point in the cell. This point in needed to close the polygon
              firstOfCell = new Point2D;
              *firstOfCell = pt2d;
              lastPoint = new Point2D;
              *lastPoint = pt2d;
              lastPointId = *cellIdIt;
            }
            else
            {
              if (lineSelected)
              {
                glColor3f(selectedColor[0],selectedColor[1],selectedColor[2]);//red
                //a line from lastPoint to thisPoint
                glBegin (GL_LINES);
                  glVertex2fv(&(*lastPoint)[0]);
                  glVertex2fv(&pt2d[0]);
                glEnd ();
              }
              else //if not selected
              {
                glColor3f(unselectedColor[0],unselectedColor[1],unselectedColor[2]);
                //drawing crosses
                glBegin (GL_LINES);
                  glVertex2fv(&(*lastPoint)[0]);
                  glVertex2fv(&pt2d[0]);
                glEnd ();
              }
              //to draw the line to the next in iteration step
              *lastPoint = pt2d;
              //and to search for the selection state of the line
              lastPointId = *cellIdIt;
            }//if..else
          }//if <4.0

          //fill off-plane polygon part 1
          if((!first) && (worldplanegeometry!=NULL))
          {
            line.SetPoints(lastPoint3D, thisPoint);
            if(worldplanegeometry->IntersectionPointParam(line, t) &&
              ((t>=0) && (t<=1))
              )
            {
              intersectionPoints.push_back(line.GetPoint(t));
            }
          }
          ++cellIdIt;
          first=false;
        }//while cellIdIter

        //closed polygon?
        if ( cellDataIt->Value().closed )
        {
          //close the polygon if needed
          if( firstOfCell != NULL )
          {
            lineSelected = false;
            Mesh::SelectedLinesType selectedLines = cellDataIt->Value().selectedLines;
            Mesh::SelectedLinesIter position = std::find(selectedLines.begin(), selectedLines.end(), lastPointId);
            if (position != selectedLines.end())//found the index
            {
              glColor3f(selectedColor[0],selectedColor[1],selectedColor[2]);//red
              //a line from lastPoint to firstPoint
              glBegin (GL_LINES);
                glVertex2fv(&(*lastPoint)[0]);
                glVertex2fv(&(*firstOfCell)[0]);
              glEnd ();
            }
            else
            {
              glColor3f(unselectedColor[0],unselectedColor[1],unselectedColor[2]);
              glBegin (GL_LINES);
                glVertex2fv(&(*lastPoint)[0]);
                glVertex2fv(&(*firstOfCell)[0]);
              glEnd ();
            }
          }
        }//if closed

        //Axis-aligned bounding box(AABB) around the cell if selected and set in Property
        bool showBoundingBox;
        if (dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("showBoundingBox")) == NULL)
          showBoundingBox = false;
        else
          showBoundingBox = dynamic_cast<mitk::BoolProperty *>(this->GetDataNode()->GetProperty("showBoundingBox"))->GetValue();

        if(showBoundingBox)
        {
          if (cellDataIt->Value().selected)
          {
            mitk::Mesh::DataType::BoundingBoxPointer aABB = input->GetBoundingBoxFromCell(cellIt->Index());
            if (aABB.IsNotNull())
            {
              mitk::Mesh::PointType min, max;
              min = aABB->GetMinimum();
              max = aABB->GetMaximum();

              //project to the displayed geometry
              Point2D min2D, max2D;
              Point3D p, projected_p;
              float vtkp[3];
              itk2vtk(min, vtkp);
              transform->TransformPoint(vtkp, vtkp);
              vtk2itk(vtkp,p);
              displayGeometry->Project(p, projected_p);
              displayGeometry->Map(projected_p, min2D);
              displayGeometry->WorldToDisplay(min2D, min2D);

              itk2vtk(max, vtkp);
              transform->TransformPoint(vtkp, vtkp);
              vtk2itk(vtkp,p);
              displayGeometry->Project(p, projected_p);
              Vector3D diff=p-projected_p;
              if(diff.GetSquaredNorm()<4.0)
              {
                displayGeometry->Map(projected_p, max2D);
                displayGeometry->WorldToDisplay(max2D, max2D);

                //draw the BoundingBox
                glColor3f(selectedColor[0],selectedColor[1],selectedColor[2]);//red
                //a line from lastPoint to firstPoint
                glBegin(GL_LINE_LOOP);
                  glVertex2f(min2D[0], min2D[1]);
                  glVertex2f(min2D[0], max2D[1]);
                  glVertex2f(max2D[0], max2D[1]);
                  glVertex2f(max2D[0], min2D[1]);
                glEnd();
              }//draw bounding-box
            }//bounding-box exists
          }//cell selected
        }//show bounding-box

        //fill off-plane polygon part 2
        if(worldplanegeometry!=NULL)
        {
          //consider line from last to first
          line.SetPoints(thisPoint, firstOfCell3D);
          if(worldplanegeometry->IntersectionPointParam(line, t) &&
            ((t>=0) && (t<=1))
            )
          {
            intersectionPoints.push_back(line.GetPoint(t));
          }
          std::sort(intersectionPoints.begin(), intersectionPoints.end(), point3DSmaller);
          std::vector<mitk::Point3D>::iterator it, end;
          end=intersectionPoints.end();
          if((intersectionPoints.size()%2)!=0)
          {
            --end; //ensure even number of intersection-points
          }
          float p[2];
          Point3D pt3d;
          Point2D pt2d;
          for ( it = intersectionPoints.begin( ); it != end; ++it )
          {
            glBegin (GL_LINES);
              displayGeometry->Map(*it, pt2d); displayGeometry->WorldToDisplay(pt2d, pt2d);
              p[0] = pt2d[0]; p[1] = pt2d[1]; glVertex2fv(p);
              ++it;
              displayGeometry->Map(*it, pt2d); displayGeometry->WorldToDisplay(pt2d, pt2d);
              p[0] = pt2d[0]; p[1] = pt2d[1]; glVertex2fv(p);
            glEnd ();
          }
          if(it!=intersectionPoints.end())
          {
            glBegin (GL_LINES);
              displayGeometry->Map(*it, pt2d); displayGeometry->WorldToDisplay(pt2d, pt2d);
              p[0] = pt2d[0]; p[1] = pt2d[1]; glVertex2fv(p);
              p[0] = pt2d[0]; p[1] = pt2d[1]; glVertex2fv(p);
            glEnd ();
          }
        }//fill off-plane polygon part 2
      }//if numOfPointsInCell>1
      delete firstOfCell;
      delete lastPoint;
      lastPoint = NULL;
      firstOfCell = NULL;
      lastPointId = 0;
      ++cellIt;
      ++cellDataIt;
    }
  }
}
Пример #10
0
void mitk::PolyDataGLMapper2D::Paint( mitk::BaseRenderer * renderer )
{
    if ( IsVisible( renderer ) == false )
        return ;

    // ok, das ist aus GenerateData kopiert
    mitk::BaseData::Pointer input = const_cast<mitk::BaseData*>( GetData() );

    assert( input );

    input->Update();

    vtkPolyData * vtkpolydata = this->GetVtkPolyData();
    assert( vtkpolydata );


    vtkLinearTransform * vtktransform = GetDataNode() ->GetVtkTransform();

    if (vtktransform)
    {
      vtkLinearTransform * inversetransform = vtktransform->GetLinearInverse();

      Geometry2D::ConstPointer worldGeometry = renderer->GetCurrentWorldGeometry2D();
      PlaneGeometry::ConstPointer worldPlaneGeometry = dynamic_cast<const PlaneGeometry*>( worldGeometry.GetPointer() );

      if ( vtkpolydata != NULL )
      {
          Point3D point;
          Vector3D normal;

          if(worldPlaneGeometry.IsNotNull())
          {
            // set up vtkPlane according to worldGeometry
            point=worldPlaneGeometry->GetOrigin();
            normal=worldPlaneGeometry->GetNormal(); normal.Normalize();
            m_Plane->SetTransform((vtkAbstractTransform*)NULL);
          }
          else
          {
            //@FIXME: does not work correctly. Does m_Plane->SetTransform really transforms a "plane plane" into a "curved plane"?
            return;
            AbstractTransformGeometry::ConstPointer worldAbstractGeometry = dynamic_cast<const AbstractTransformGeometry*>(renderer->GetCurrentWorldGeometry2D());
            if(worldAbstractGeometry.IsNotNull())
            {
              // set up vtkPlane according to worldGeometry
              point=const_cast<mitk::BoundingBox*>(worldAbstractGeometry->GetParametricBoundingBox())->GetMinimum();
              FillVector3D(normal, 0, 0, 1);
              m_Plane->SetTransform(worldAbstractGeometry->GetVtkAbstractTransform()->GetInverse());
            }
            else
              return;
          }

          vtkFloatingPointType vp[ 3 ], vnormal[ 3 ];

          vnl2vtk(point.Get_vnl_vector(), vp);
          vnl2vtk(normal.Get_vnl_vector(), vnormal);

          //normally, we would need to transform the surface and cut the transformed surface with the cutter.
          //This might be quite slow. Thus, the idea is, to perform an inverse transform of the plane instead.
          //@todo It probably does not work for scaling operations yet:scaling operations have to be
          //dealed with after the cut is performed by scaling the contour.
          inversetransform->TransformPoint( vp, vp );
          inversetransform->TransformNormalAtPoint( vp, vnormal, vnormal );

          m_Plane->SetOrigin( vp );
          m_Plane->SetNormal( vnormal );

          // set data into cutter
          m_Cutter->SetInput( vtkpolydata );
          //    m_Cutter->GenerateCutScalarsOff();
          //    m_Cutter->SetSortByToSortByCell();

          // calculate the cut
          m_Cutter->Update();

          // fetch geometry
          mitk::DisplayGeometry::Pointer displayGeometry = renderer->GetDisplayGeometry();
          assert( displayGeometry );
          //  float toGL=displayGeometry->GetSizeInDisplayUnits()[1];

          //apply color and opacity read from the PropertyList
          ApplyProperties( renderer );

          // traverse the cut contour
          vtkPolyData * contour = m_Cutter->GetOutput();

          vtkPoints *vpoints = contour->GetPoints();
          vtkCellArray *vpolys = contour->GetLines();
          vtkPointData *vpointdata = contour->GetPointData();
          vtkDataArray* vscalars = vpointdata->GetScalars();

          vtkCellData *vcelldata = contour->GetCellData();
          vtkDataArray* vcellscalars = vcelldata->GetScalars();

          int i, numberOfCells = vpolys->GetNumberOfCells();

          Point3D p;
          Point2D p2d, last, first;

          vpolys->InitTraversal();
          vtkScalarsToColors* lut = GetVtkLUT();
          assert ( lut != NULL );

          for ( i = 0;i < numberOfCells;++i )
          {
              vtkIdType *cell(NULL);
              vtkIdType cellSize(0);

              vpolys->GetNextCell( cellSize, cell );

              if ( m_ColorByCellData )
              {  // color each cell according to cell data
                vtkFloatingPointType* color = lut->GetColor( vcellscalars->GetComponent( i, 0 ) );
                glColor3f( color[ 0 ], color[ 1 ], color[ 2 ] );
              }
              if ( m_ColorByPointData )
              {
                vtkFloatingPointType* color = lut->GetColor( vscalars->GetComponent( cell[0], 0 ) );
                glColor3f( color[ 0 ], color[ 1 ], color[ 2 ] );
              }

              glBegin ( GL_LINE_LOOP );
              for ( int j = 0;j < cellSize;++j )
              {
                  vpoints->GetPoint( cell[ j ], vp );
                  //take transformation via vtktransform into account
                  vtktransform->TransformPoint( vp, vp );

                  vtk2itk( vp, p );

                  //convert 3D point (in mm) to 2D point on slice (also in mm)
                  worldGeometry->Map( p, p2d );

                  //convert point (until now mm and in worldcoordinates) to display coordinates (units )
                  displayGeometry->WorldToDisplay( p2d, p2d );

                  //convert display coordinates ( (0,0) is top-left ) in GL coordinates ( (0,0) is bottom-left )
                  //p2d[1]=toGL-p2d[1];

                  //add the current vertex to the line
                  glVertex2f( p2d[0], p2d[1] );
              }
              glEnd ();
          }
      }
    }
}
void mitk::ToFSurfaceVtkMapper3D::GenerateDataForRenderer(mitk::BaseRenderer* renderer)
{
  LocalStorage *ls = m_LSH.GetLocalStorage(renderer);

  bool visible = IsVisible(renderer);

  if(visible==false)
  {
    ls->m_Actor->VisibilityOff();
    return;
  }

  //
  // set the input-object at time t for the mapper
  //
  //mitk::ToFSurface::Pointer input  = const_cast< mitk::ToFSurface* >( this->GetInput() );
  mitk::Surface::Pointer input  = const_cast< mitk::Surface* >( this->GetInput() );
  vtkPolyData * polydata = input->GetVtkPolyData( this->GetTimestep() );
  if(polydata == NULL) 
  {
    ls->m_Actor->VisibilityOff();
    return;
  }

  if ( m_GenerateNormals )
  {
    ls->m_VtkPolyDataNormals->SetInput( polydata );
    ls->m_VtkPolyDataMapper->SetInput( ls->m_VtkPolyDataNormals->GetOutput() );
  }
  else
  {
    ls->m_VtkPolyDataMapper->SetInput( polydata );
  }

  //
  // apply properties read from the PropertyList
  //
  ApplyProperties(ls->m_Actor, renderer);

  if(visible)
    ls->m_Actor->VisibilityOn();

  //
  // TOF extension for visualization (color/texture mapping)
  //
  if (this->m_VtkScalarsToColors)
  {
    // set the color transfer funtion if applied
    ls->m_VtkPolyDataMapper->SetLookupTable(this->m_VtkScalarsToColors);
  }

  if (this->m_Texture)
  {
    // create a vtk image as basic for texture
    vtkImageData* imageData = vtkImageData::New();
    int width = this->m_TextureWidth;
    int height = this->m_TextureHeight;
    imageData->SetDimensions(width, height, 1);
    imageData->SetScalarTypeToUnsignedChar();
    imageData->SetNumberOfScalarComponents(3); // RGB
    imageData->SetSpacing(0.0, 0.0, 0.0);
    imageData->SetOrigin(width/2, height/2, 0.0);
    imageData->AllocateScalars(); // allocate storage for image data
    imageData->SetScalarType( VTK_UNSIGNED_CHAR );

    // create a vtk array to hold the input unsigned char* texture (e.g. from the video camera)
    vtkDataArray *scalars;
    scalars = vtkUnsignedCharArray::New();
    scalars->SetNumberOfComponents(3);
    scalars->SetVoidArray(this->GetTexture(), width*height*3, 1);

    // prepare the image data from vtk array
    imageData->GetPointData()->SetScalars(scalars);
    scalars->Delete();

    // create vtk texture 
    vtkTexture *aTexture = vtkTexture::New(); 
    aTexture->SetInput(imageData); 
    aTexture->InterpolateOn();
    ls->m_Actor->SetTexture(aTexture);
    aTexture->Delete();
  }
  else
  {
    // remove the texture
    ls->m_Actor->SetTexture(0);
  }
}