Esempio n. 1
0
 def to_point(self, centers, falloff):
     n = len(centers)
     if n == 1:
         sfield = SvScalarFieldPointDistance(centers[0], falloff=falloff)
         vfield = SvVectorFieldPointDistance(centers[0], falloff=falloff)
     elif self.point_mode == 'AVG':
         sfields = [
             SvScalarFieldPointDistance(center, falloff=falloff)
             for center in centers
         ]
         sfield = SvMergedScalarField('AVG', sfields)
         vfields = [
             SvVectorFieldPointDistance(center, falloff=falloff)
             for center in centers
         ]
         vfield = SvAverageVectorField(vfields)
     elif self.point_mode == 'MIN':
         kdt = kdtree.KDTree(len(centers))
         for i, v in enumerate(centers):
             kdt.insert(v, i)
         kdt.balance()
         vfield = SvKdtVectorField(kdt=kdt, falloff=falloff)
         sfield = SvKdtScalarField(kdt=kdt, falloff=falloff)
     else:  # SEP
         sfield = [
             SvScalarFieldPointDistance(center, falloff=falloff)
             for center in centers
         ]
         vfield = [
             SvVectorFieldPointDistance(center, falloff=falloff)
             for center in centers
         ]
     return vfield, sfield
Esempio n. 2
0
 def to_point(self, centers, falloff):
     if self.metric == 'DISTANCE':
         metric_single = 'EUCLIDEAN'
     else:
         metric_single = self.metric
     n = len(centers)
     if n == 1:
         sfield = SvScalarFieldPointDistance(centers[0],
                                             falloff=falloff,
                                             metric=metric_single,
                                             power=self.get_power())
         vfield = SvVectorFieldPointDistance(centers[0],
                                             falloff=falloff,
                                             metric=metric_single,
                                             power=self.get_power())
     elif self.merge_mode == 'AVG':
         sfields = [
             SvScalarFieldPointDistance(center,
                                        falloff=falloff,
                                        metric=metric_single,
                                        power=self.get_power())
             for center in centers
         ]
         sfield = SvMergedScalarField('AVG', sfields)
         vfields = [
             SvVectorFieldPointDistance(center,
                                        falloff=falloff,
                                        metric=metric_single,
                                        power=self.get_power())
             for center in centers
         ]
         vfield = SvAverageVectorField(vfields)
     elif self.merge_mode == 'MIN':
         kdt = SvKdTree.new(SvKdTree.best_available_implementation(),
                            centers,
                            power=self.get_power())
         vfield = SvKdtVectorField(kdt=kdt, falloff=falloff)
         sfield = SvKdtScalarField(kdt=kdt, falloff=falloff)
     else:  # SEP
         sfield = [
             SvScalarFieldPointDistance(center,
                                        falloff=falloff,
                                        metric=metric_single,
                                        power=self.get_power())
             for center in centers
         ]
         vfield = [
             SvVectorFieldPointDistance(center,
                                        falloff=falloff,
                                        metric=metric_single,
                                        power=self.get_power())
             for center in centers
         ]
     return vfield, sfield
Esempio n. 3
0
    def process(self):
        if not any(socket.is_linked for socket in self.outputs):
            return

        center_s = self.inputs['Center'].sv_get()
        amplitudes_s = self.inputs['Amplitude'].sv_get(default=[0.5])
        coefficients_s = self.inputs['Coefficient'].sv_get(default=[0.5])

        fields_out = []
        for centers, amplitudes, coefficients in zip_long_repeat(
                center_s, amplitudes_s, coefficients_s):
            for center, amplitude, coefficient in zip_long_repeat(
                    centers, amplitudes, coefficients):
                if self.falloff_type == 'NONE':
                    falloff_func = None
                else:
                    falloff_func = falloff_array(self.falloff_type, amplitude,
                                                 coefficient, self.clamp)
                field = SvScalarFieldPointDistance(np.array(center),
                                                   metric=self.metric,
                                                   power=self.power,
                                                   falloff=falloff_func)
                fields_out.append(field)

        self.outputs['Field'].sv_set(fields_out)