Example #1
0
def main():
    #SHOWING INITIAL INSTRUNCTION ON TERMINAL
    print("Dynamic Bezier Curve Interactor")
    print("Made by:")
    print("\tLeonardo Da Vinci (lvfs)")
    print("\tHeitor Fontes (hfxc)")
    print("\nInstructions:")
    print("\t1. click to add a point")
    print("\t2. press 'b' to calculate and show the bezier curve")
    print("\t3. press 'v' to to toggle the bezier curve view")
    print("\t4. press 'd' to calculate and show the derivaties curves")
    print("\t5. press 's' to toggle the derivaties curves view")
    print("\t6. press 'space' to toggle the control curve view")
    print("\t7. press 'c' to calculate the bezier curve curvature")
    print("\t8. click on a point, hold and drag to move it")
    print("\t9. move the mouse upon a point and press 'del' to delete it")

    global mcurve
    global curvature
    global curvature_canva

    #CREATING MAIN CANVA
    tkroot = tk.Tk()
    scrw = tkroot.winfo_screenwidth()  #screen width
    scrh = tkroot.winfo_screenheight()  #screen height
    width = round(scrw / 2) - 10  #window width
    height = scrh  #window height
    tkroot.geometry(str(width) + "x" + str(height) + "+0+0")
    tkroot.title("Main Window")
    print("screen resolution: " + str(scrw) + "x" + str(scrh))
    frame = tk.Canvas(tkroot, width=width, height=height)
    # frame = tk.Canvas(tkroot, width=scrw, height=scrh)
    # tkroot.attributes("-fullscreen", True)
    tkroot.bind('<Button-1>', lambda event: onclick(event, canva=frame))
    tkroot.bind("<Key>", lambda event: keypress(event, canva=frame))
    tkroot.bind("<B1-Motion>", lambda event: onmove(event, canva=frame))
    tkroot.bind("<ButtonRelease-1>", stopMoving)
    tkroot.bind("<Key-space>",
                lambda event: toggle_control_lines(event, canva=frame))
    tkroot.bind("<Delete>", lambda event: delete(event, canva=frame))
    frame.pack()

    #CREATING CURVATURE CANVA
    curve_window = tk.Toplevel()
    curve_window.title("Curvature")
    curve_window.geometry(str(width) + "x" + str(height) + "-0+0")
    curvature_canva = tk.Canvas(curve_window, width=width, height=height)
    curvature_canva.pack()

    tkroot.lift(aboveThis=curve_window)

    curvature = Curvature(width, height)

    tk.mainloop()
Example #2
0
    def calculateCurvature(self,
                           smooth=True,
                           window=2,
                           smoothedContour=False,
                           percentiles=[99, 1]):
        """
        Calculate the curvature based on the expression for local curvature
        ( see https://en.wikipedia.org/wiki/Curvature#Local_expressions )
        
        Input:
          smooth (bool):  Smooth the curvature data using the gaussian weighted
                          rolling window approach.
            
          window (float):  Sigma of the gaussian (The three sigma range of the
                           gaussian will be used for the averaging with each 
                           localisation weighted according to the value of 
                           the gaussian).
        
          smoothedContour (boolean): Use the smoothed contour for the calculation?
                                     Default is False.
        
          isclosed (boolean): REMOVED 
            
                              Each contour is checked if it closed, i.e. start
                              and end point fall close in space and treated
                              accordingly. For open contours the endings are
                              ignored to avoid bias from the edges.
                                
                              Treat the contour as closed path. Default is True
                              and should always be the case if padding was added
                              to the image when loading image files or when the
                              FOV was sufficiently large when loading point
                              localisation data. Note that there might be unexpected
                              if the contour is not closed.
        
          percentiles (list): Must be a list of two floats. Specifies the max and
                              min values for displaying the curvature on a color
                              scale. This can be important if unnatural kinks are
                              observed which would dominate the curvature to an
                              extent that the color scale would be skewed.
                              By setting the percentiles one can set the range
                              in a "smart" way.
        
        """
        if self.contour is None:
            print('You need to run the contour selection first!')
            return

        self.curvature = Curvature()
        self.curvature.setData(
            self.contour.getResult(smoothed=smoothedContour))
        self.curvature.calculateCurvature(smooth=smooth,
                                          window=window,
                                          percentiles=percentiles)
Example #3
0
    def T(self):
        """Determines the DCP attributes of a transpose.

        Returns:
            The DCPAttr of the transpose of the matrix expression.
        """
        rows, cols = self.shape.size
        shape = Shape(cols, rows)

        neg_mat = self.sign.neg_mat.T
        pos_mat = self.sign.pos_mat.T
        cvx_mat = self.curvature.cvx_mat.T
        conc_mat = self.curvature.conc_mat.T
        nonconst_mat = self.curvature.nonconst_mat.T

        return DCPAttr(Sign(neg_mat, pos_mat),
                       Curvature(cvx_mat, conc_mat, nonconst_mat), shape)
Example #4
0
    def __getitem__(self, key):
        """Determines the DCP attributes of an index/slice.

        Args:
            key: A (slice, slice) tuple.

        Returns:
            The DCPAttr of the index/slice into the matrix expression.
        """
        shape = Shape(*ku.size(key, self.shape))

        # Reduce 1x1 matrices to scalars.
        neg_mat = bu.to_scalar(bu.index(self.sign.neg_mat, key))
        pos_mat = bu.to_scalar(bu.index(self.sign.pos_mat, key))
        cvx_mat = bu.to_scalar(bu.index(self.curvature.cvx_mat, key))
        conc_mat = bu.to_scalar(bu.index(self.curvature.conc_mat, key))
        nonconst_mat = bu.to_scalar(bu.index(self.curvature.nonconst_mat, key))

        return DCPAttr(Sign(neg_mat, pos_mat),
                       Curvature(cvx_mat, conc_mat, nonconst_mat), shape)
Example #5
0
    def setup(self):
        nn = self.options['num_nodes']

        self.add_subsystem(name='normal',
                           subsys=NormalForceODE(num_nodes=nn),
                           promotes_inputs=['ax', 'ay', 'V'],
                           promotes_outputs=['N_fr', 'N_fl', 'N_rr', 'N_rl'])

        self.add_subsystem(name='tire',
                           subsys=TireODE(num_nodes=nn),
                           promotes_inputs=[
                               'lambda', 'omega', 'V', 'N_fr', 'N_fl', 'N_rr',
                               'N_rl', 'thrust', 'delta'
                           ],
                           promotes_outputs=[
                               'S_fr', 'S_fl', 'S_rr', 'S_rl', 'F_fr', 'F_fl',
                               'F_rr', 'F_rl'
                           ])

        self.add_subsystem(name='curv', subsys=Curvature(num_nodes=nn))

        self.connect('curv.kappa', 'car.kappa')

        self.add_subsystem(name='car',
                           subsys=CarODE(num_nodes=nn),
                           promotes_inputs=[
                               'n', 'alpha', 'V', 'lambda', 'omega', 'S_fr',
                               'S_fl', 'S_rr', 'S_rl', 'F_fr', 'F_fl', 'F_rr',
                               'F_rl', 'delta'
                           ],
                           promotes_outputs=[
                               'sdot', 'ndot', 'alphadot', 'omegadot', 'Vdot',
                               'lambdadot', 'power'
                           ])

        self.add_subsystem(name='accel',
                           subsys=AccelerationODE(num_nodes=nn),
                           promotes_inputs=[
                               'V', 'lambda', 'omega', 'Vdot', 'lambdadot',
                               'ax', 'ay'
                           ],
                           promotes_outputs=['axdot', 'aydot'])

        self.add_subsystem(name='tireconstraint',
                           subsys=TireConstraintODE(num_nodes=nn),
                           promotes_inputs=[
                               'S_fr', 'S_fl', 'S_rr', 'S_rl', 'F_fr', 'F_fl',
                               'F_rr', 'F_rl', 'N_fr', 'N_fl', 'N_rr', 'N_rl'
                           ],
                           promotes_outputs=['c_rr', 'c_rl', 'c_fr', 'c_fl'])

        self.add_subsystem(name='time',
                           subsys=TimeODE(num_nodes=nn),
                           promotes_inputs=[
                               'ndot', 'sdot', 'omegadot', 'lambdadot', 'Vdot',
                               'axdot', 'aydot', 'alphadot'
                           ],
                           promotes_outputs=[
                               'dn_ds', 'dV_ds', 'domega_ds', 'dlambda_ds',
                               'dalpha_ds', 'dax_ds', 'day_ds'
                           ])

        self.add_subsystem(name='timeAdder',
                           subsys=TimeAdder(num_nodes=nn),
                           promotes_inputs=['sdot'],
                           promotes_outputs=['dt_ds'])
Example #6
0
    m2, c2 = get_line_equation([b[0], c[0]], [b[1], c[1]])

    k1, b1 = get_parameters_of_normal(m1, (a[0] + b[0]) / 2, (a[1] + b[1]) / 2)
    k2, b2 = get_parameters_of_normal(m2, (c[0] + b[0]) / 2, (c[1] + b[1]) / 2)

    xi, yi = get_normal_intersection_point(k1, k2, b1, b2)

    curvature = get_cauchy_curvature(xi, b[0], yi, b[1])
    return curvature


a = np.linspace(-5, 5, 300)
b = sigmoid(a)
line = [(i, j) for i, j in zip(a, b)]

curv = Curvature(line=line)

start = time.time()
curv.calculate_curvature()
end = time.time()
print(end - start)

cauchy_curvature = []
start = time.time()
for i in range(1, 299):
    cauchy_curvature.append(calculate_cauchy_curvature_from_triplet(*line[i-1:i+2]))
end = time.time()
print(end - start)

xc = range(len(curv.curvature))
plt.plot(xc, curv.curvature)