void
CompliantPlannerDlg::generateButtonClicked()
{
	int resolution = resolutionEdit->text().toInt();
	if (resolution < 1) {
		DBGA("Resolution must be at least 1");
		return;
	}
	//get object bbox dimensions
	SoGetBoundingBoxAction *bba = 
		new SoGetBoundingBoxAction(graspitCore->getIVmgr()->getViewer()->getViewportRegion());
	bba->apply(mObject->getIVGeomRoot());
	SbVec3f bbmin,bbmax;
	bba->getBoundingBox().getBounds(bbmin,bbmax);
	delete bba;
	double a = 0.5*(bbmax[0] - bbmin[0]);
	double b = 0.5*(bbmax[1] - bbmin[1]);
	double c = 0.5*(bbmax[2] - bbmin[2]);
	//ellipsoidSampling(a,b,c,resolution);
	boxSampling(a,b,c, resolution);

	mPlanner->resetPlanner();
	if (visualMarkersBox->isChecked()) {
		visualMarkersBoxClicked();
	}
	update();
}
SbBox3f ViewProviderDatum::getRelevantBoundBox (
    SoGetBoundingBoxAction &bboxAction, const std::vector <App::DocumentObject *> &objs )
{
    SbBox3f bbox(0,0,0, 0,0,0);

    // Adds the bbox of given feature to the output
    for (auto obj :objs) {
        ViewProvider *vp = Gui::Application::Instance->getViewProvider(obj);
        if (!vp) {
            continue;
        }
        if (!vp->isVisible ()) {
            continue;
        }

        if (obj->isDerivedFrom (Part::Datum::getClassTypeId() ) ) {
            // Treat datums only as their basepoint
            // I hope it's ok to take FreeCAD's point here
            Base::Vector3d basePoint = static_cast<Part::Datum *> ( obj )->getBasePoint ();
            bbox.extendBy (SbVec3f(basePoint.x, basePoint.y, basePoint.z ));
        } else {
            bboxAction.apply ( vp->getRoot () );
            SbBox3f obj_bbox =  bboxAction.getBoundingBox ();

            if ( obj_bbox.getVolume () < Precision::Infinite () ) {
                bbox.extendBy ( obj_bbox );
            }
        }
    }

    return bbox;
}
Esempio n. 3
0
/*!
  This is a static "helper" method registered with the action, and
  used for calling the SoNode::getBoundingBox() virtual method which
  does the \e real work.
*/
void
SoNode::getBoundingBoxS(SoAction * action, SoNode * node)
{
  assert(action && node);
  SoGetBoundingBoxAction * bboxaction = (SoGetBoundingBoxAction *)action;
  bboxaction->checkResetBefore();
  node->getBoundingBox(bboxaction);
  bboxaction->checkResetAfter();
}
/*!
 This implements typical action traversal for an SoComplexShape node
*/
void
SoComplexShape::doAction(SoAction *action)
{
  // Make sure all the children exist
  if (children->getLength() == 0) { generateChildren(); }

  // SoAction has a method called "getPathCode()" that returns
  // a code indicating how this node is related to the path(s)
  // the action is being applied to. This code is one of the
  // following:
  //
  // NO_PATH    = Not traversing a path (action was applied
  //                to a node)
  // IN_PATH    = This node is in the path chain, but is not
  //                the tail node
  // BELOW_PATH = This node is the tail of the path chain or
  //                is below the tail
  // OFF_PATH   = This node is off to the left of some node in
  //                the path chain
  //
  // If getPathCode() returns IN_PATH, it returns (in its two
  // arguments) the indices of the next nodes in the paths.
  // (Remember that an action can be applied to a list of
  // paths.)

  // For the IN_PATH case, these will be set by getPathCode()
  // to contain the number of child nodes that are in paths and
  // the indices of those children, respectively. In the other
  // cases, they are not meaningful.
  int         numIndices;
  const int   *indices;

  // This will be set to the index of the last (rightmost)
  // child to traverse
  int         lastChildIndex;

  // If this node is in a path, see which of our children are
  // in paths, and traverse up to and including the rightmost
  // of these nodes (the last one in the "indices" array).
  if (action->getPathCode(numIndices, indices) ==
      SoAction::IN_PATH) {
    lastChildIndex = indices[numIndices - 1];
  }

  // Otherwise, consider all of the children
  else {
    lastChildIndex = children->getLength() - 1;
  }

  // Now we are ready to traverse the children, skipping every
  // other one. For the SoGetBoundingBoxAction, however, we
  // have to do some extra work in between each pair of
  // children - we have to make sure the center points get
  // averaged correctly.
  if (action->isOfType(
        SoGetBoundingBoxAction::getClassTypeId())) {
    SoGetBoundingBoxAction *bba =
      (SoGetBoundingBoxAction *) action;
    SbVec3f  totalCenter(0.0, 0.0, 0.0);
    int      numCenters = 0;

    for (int i = 0; i <= lastChildIndex; i++) {
      children->traverse(bba, i);

      // If the traversal set a center point in the action,
      // add it to the total and reset for the next child.
      if (bba->isCenterSet()) {
        totalCenter += bba->getCenter();
        numCenters++;
        bba->resetCenter();
      }
    }
    // Now, set the center to be the average. Since the
    // centers were already transformed, there's no need to
    // transform the average.
    if (numCenters != 0) {
      bba->setCenter(totalCenter / (float)numCenters, FALSE);
    }
  }

  // For all other actions, just traverse every child
  else
    for (int i = 0; i <= lastChildIndex; i++) {
      children->traverse(action, i);
    }
}
Esempio n. 5
0
/*
 * Fun flux analysis
 */
void FluxAnalysis::RunFluxAnalysis( QString nodeURL, QString surfaceSide, unsigned long nOfRays, bool increasePhotonMap, int heightDivisions, int widthDivisions )
{
	m_surfaceURL = nodeURL;
	m_surfaceSide = surfaceSide;

	//Delete a photonCounts
	if( m_photonCounts && m_photonCounts != 0 )
	{
		for( int h = 0; h < m_heightDivisions; h++ )
		{
			delete[] m_photonCounts[h];
		}

		delete[] m_photonCounts;
	}
	m_photonCounts = 0;
	m_heightDivisions = heightDivisions;
	m_widthDivisions = widthDivisions;

	//Check if there is a scene
	if ( !m_pCurrentScene )  return;

	//Check if there is a transmissivity defined
	TTransmissivity* transmissivity = 0;
	if ( !m_pCurrentScene->getPart( "transmissivity", false ) )	transmissivity = 0;
	else
		transmissivity = static_cast< TTransmissivity* > ( m_pCurrentScene->getPart( "transmissivity", false ) );

	//Check if there is a rootSeparator InstanceNode
	if( !m_pRootSeparatorInstance ) return;

	InstanceNode* sceneInstance = m_pRootSeparatorInstance->GetParent();
	if ( !sceneInstance )  return;

	//Check if there is a light and is properly configured
	if ( !m_pCurrentScene->getPart( "lightList[0]", false ) )return;
	TLightKit* lightKit = static_cast< TLightKit* >( m_pCurrentScene->getPart( "lightList[0]", false ) );

	InstanceNode* lightInstance = sceneInstance->children[0];
	if ( !lightInstance ) return;

	if( !lightKit->getPart( "tsunshape", false ) ) return;
	TSunShape* sunShape = static_cast< TSunShape * >( lightKit->getPart( "tsunshape", false ) );

	if( !lightKit->getPart( "icon", false ) ) return;
	TLightShape* raycastingSurface = static_cast< TLightShape * >( lightKit->getPart( "icon", false ) );

	if( !lightKit->getPart( "transform" ,false ) ) return;
	SoTransform* lightTransform = static_cast< SoTransform * >( lightKit->getPart( "transform" ,false ) );

	//Check if there is a random generator is defined.
	if( !m_pRandomDeviate || m_pRandomDeviate== 0 )	return;

	//Check if the surface and the surface side defined is suitable
	if( CheckSurface() == false || CheckSurfaceSide() == false ) return;

	//Create the photon map where photons are going to be stored
	if( !m_pPhotonMap  || !increasePhotonMap )
	{
		if( m_pPhotonMap ) 	m_pPhotonMap->EndStore( -1 );
		delete m_pPhotonMap;
		m_pPhotonMap = new TPhotonMap();
		m_pPhotonMap->SetBufferSize( HUGE_VAL );
		m_tracedRays = 0;
		m_wPhoton = 0;
		m_totalPower = 0;
	}

	QVector< InstanceNode* > exportSuraceList;
	QModelIndex nodeIndex = m_pCurrentSceneModel->IndexFromNodeUrl( m_surfaceURL );
	if( !nodeIndex.isValid()  )	return;

	InstanceNode* surfaceNode = m_pCurrentSceneModel->NodeFromIndex( nodeIndex );
	if( !surfaceNode || surfaceNode == 0 )	return;
	exportSuraceList.push_back( surfaceNode );

	//UpdateLightSize();
	TSeparatorKit* concentratorRoot = static_cast< TSeparatorKit* >( m_pCurrentScene->getPart( "childList[0]", false ) );
	if ( !concentratorRoot )	return;

	SoGetBoundingBoxAction* bbAction = new SoGetBoundingBoxAction( SbViewportRegion() ) ;
	concentratorRoot->getBoundingBox( bbAction );

	SbBox3f box = bbAction->getXfBoundingBox().project();
	delete bbAction;
	bbAction = 0;

	BBox sceneBox;
	if( !box.isEmpty() )
	{
		sceneBox.pMin = Point3D( box.getMin()[0], box.getMin()[1], box.getMin()[2] );
		sceneBox.pMax = Point3D( box.getMax()[0], box.getMax()[1], box.getMax()[2] );
		if( lightKit ) lightKit->Update( sceneBox );
	}

	m_pCurrentSceneModel->UpdateSceneModel();

	//Compute bounding boxes and world to object transforms
	trf::ComputeSceneTreeMap( m_pRootSeparatorInstance, Transform( new Matrix4x4 ), true );

	m_pPhotonMap->SetConcentratorToWorld( m_pRootSeparatorInstance->GetIntersectionTransform() );

	QStringList disabledNodes = QString( lightKit->disabledNodes.getValue().getString() ).split( ";", QString::SkipEmptyParts );
	QVector< QPair< TShapeKit*, Transform > > surfacesList;
	trf::ComputeFistStageSurfaceList( m_pRootSeparatorInstance, disabledNodes, &surfacesList );
	lightKit->ComputeLightSourceArea( m_sunWidthDivisions, m_sunHeightDivisions, surfacesList );
	if( surfacesList.count() < 1 )	return;

	QVector< long > raysPerThread;
	int maximumValueProgressScale = 100;

	unsigned long  t1 = nOfRays/ maximumValueProgressScale;
	for( int progressCount = 0; progressCount < maximumValueProgressScale; ++ progressCount )
		raysPerThread<< t1;

	if( ( t1 * maximumValueProgressScale ) < nOfRays )	raysPerThread<< ( nOfRays - ( t1* maximumValueProgressScale) );

	Transform lightToWorld = tgf::TransformFromSoTransform( lightTransform );
	lightInstance->SetIntersectionTransform( lightToWorld.GetInverse() );

	// Create a progress dialog.
	QProgressDialog dialog;
	dialog.setLabelText( QString("Progressing using %1 thread(s)..." ).arg( QThread::idealThreadCount() ) );

	// Create a QFutureWatcher and conncect signals and slots.
	QFutureWatcher< void > futureWatcher;
	QObject::connect(&futureWatcher, SIGNAL(finished()), &dialog, SLOT(reset()));
	QObject::connect(&dialog, SIGNAL(canceled()), &futureWatcher, SLOT(cancel()));
	QObject::connect(&futureWatcher, SIGNAL(progressRangeChanged(int, int)), &dialog, SLOT(setRange(int, int)));
	QObject::connect(&futureWatcher, SIGNAL(progressValueChanged(int)), &dialog, SLOT(setValue(int)));

	QMutex mutex;
	QMutex mutexPhotonMap;
	QFuture< void > photonMap;
	if( transmissivity )
		photonMap = QtConcurrent::map( raysPerThread, RayTracer( m_pRootSeparatorInstance,
							 lightInstance, raycastingSurface, sunShape, lightToWorld,
							 transmissivity,
							 *m_pRandomDeviate,
							 &mutex, m_pPhotonMap, &mutexPhotonMap,
							 exportSuraceList ) );
	else
		photonMap = QtConcurrent::map( raysPerThread, RayTracerNoTr( m_pRootSeparatorInstance,
						lightInstance, raycastingSurface, sunShape, lightToWorld,
						*m_pRandomDeviate,
						&mutex, m_pPhotonMap, &mutexPhotonMap,
						exportSuraceList ) );

	futureWatcher.setFuture( photonMap );

	// Display the dialog and start the event loop.
	dialog.exec();
	futureWatcher.waitForFinished();

	m_tracedRays += nOfRays;

	double irradiance = sunShape->GetIrradiance();
	double inputAperture = raycastingSurface->GetValidArea();
	m_wPhoton = double ( inputAperture * irradiance ) / m_tracedRays;

	UpdatePhotonCounts();
}
Esempio n. 6
0
void
SoSwitch::doChild(SoAction *action, int matchIndex)
//
////////////////////////////////////////////////////////////////////////
{
    int32_t	which;

    if (whichChild.isIgnored())
	which = SO_SWITCH_NONE;

    else
	which = whichChild.getValue();

    // If index is inherited from state, get value from there
    if (which == SO_SWITCH_INHERIT) {

	which = SoSwitchElement::get(action->getState());

	// Make sure it is in range
	if (which >= getNumChildren())
	    which %= getNumChildren();
    }

    // Store resulting index in state if not already inherited from there
    else
	SoSwitchElement::set(action->getState(), which);

    // Now we have the real value to deal with

    switch (which) {

      case SO_SWITCH_NONE:
	break;

      case SO_SWITCH_ALL:
	// If traversing to compute bounding box, we have to do some
	// work in between children
	if (action->isOfType(SoGetBoundingBoxAction::getClassTypeId())) {
	    SoGetBoundingBoxAction *bba = (SoGetBoundingBoxAction *) action;
	    SbVec3f	totalCenter(0.0, 0.0, 0.0);
	    int		numCenters = 0;
	    int 	lastChild = (matchIndex >= 0 ? matchIndex :
				     getNumChildren()  - 1);

	    for (int i = 0; i <= lastChild; i++) {
		children->traverse(bba, i, i);
		if (bba->isCenterSet()) {
		    totalCenter += bba->getCenter();
		    numCenters++;
		    bba->resetCenter();
		}
	    }
	    // Now, set the center to be the average:
	    if (numCenters != 0)
		bba->setCenter(totalCenter / numCenters, FALSE);
	}
	else {
	    if (matchIndex >= 0)
		children->traverse(action, 0, matchIndex);
	    else
		children->traverse(action);
	}
	break;

      default:

	// Make sure index is reasonable
	if (which < 0 || which >= getNumChildren()) {
#ifdef DEBUG	
	    SoDebugError::post("SoSwitch::doChild",
			       "Child index %d is out of range %d - %d "
			       "(applying %s)",
			       which, 0, getNumChildren() - 1,
			       action->getTypeId().getName().getString());
#endif /* DEBUG */			       
	    break;
	}

	// Traverse indicated child
	if (matchIndex < 0 || matchIndex == which)
	    children->traverse(action, (int) which);
    }
}