Data downsampling processing method and device
In the simulation drawing application scenario, the area range of the coordinate points is determined based on the threshold number of coordinate points accommodated by the pixel point, and redundant points are discarded. This solves the problem of browser lag caused by a large amount of coordinate point data and achieves data reduction. Sampling processing to ensure that the page is displayed normally.
Patent Information
- Application Number
- CN202410639805.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-22
- Publication Date
- 2024-09-06
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In simulation drawing application scenarios, the front-end browser receives a large number of coordinate point data, causing the page display to freeze or crash, and cannot effectively handle a large number of dense data points.
By determining the threshold of the number of coordinate points accommodated by a single pixel in the front-end browser, it is determined whether the area range of the target coordinate point and the area range of the adjacent coordinate points are the same. If they are the same, the target coordinate point will be discarded. If they are different, they will be stored in an array. , and delete redundant points in the array when necessary to reduce the amount of data drawn by the front-end browser.
Without affecting the drawing accuracy, reduce the amount of data that the front-end browser needs to draw to ensure the normal display and performance of the page.
Smart Images

Figure CN118607181A
Abstract
Description
Technical Field
[0001] The present application relates to the field of data processing technology, and in particular to a method and device for downsampling data. Background Art
[0002] In the application scenario of simulation drawing, the data generated by the simulation needs to be sent to the front-end browser, and the browser draws the corresponding chart based on the received coordinate point data. When the simulation engine generates a large amount of coordinate point data and sends it to the front-end browser, the browser needs to draw a large number of dense data points, which can easily cause the browser page display to freeze or even crash. Summary of the invention
[0003] In view of this, the present application provides a data downsampling processing method and device to reduce the amount of data drawn by the front-end browser and ensure the normal display of the page.
[0004] In a first aspect, the present application provides a method for downsampling data, the method comprising:
[0005] Determine the threshold value of the number of coordinate points that a single pixel of the front-end browser can accommodate;
[0006] For the acquired target coordinate point, when the target coordinate point is a coordinate point at a non-initial moment, an adjacent coordinate point on the target coordinate point is acquired;
[0007] Using the number threshold, determining whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs;
[0008] When the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs, the target coordinate point is discarded.
[0009] In a possible implementation, the method further includes:
[0010] When the area range to which the target coordinate point belongs is different from the area range to which the adjacent coordinate points belong, the target coordinate point is stored in an array, and the array includes the adjacent coordinate points.
[0011] In a possible implementation, the method further includes:
[0012] For any three adjacent coordinate points in the array, calculate a first slope of a line corresponding to a first coordinate point and a second coordinate point, and a second slope of a line corresponding to a third coordinate point and the second coordinate point, wherein the first coordinate point is adjacent to the second coordinate point, and the second coordinate point is adjacent to the third coordinate point;
[0013] When the first slope is the same as the second slope, the second coordinate point in the array is deleted.
[0014] In a possible implementation, the using the number threshold to determine whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs includes:
[0015] For the target coordinate point, determine a first position identifier based on the horizontal coordinate of the target coordinate point and the number threshold; determine a second position identifier based on the vertical coordinate of the target coordinate point and the number threshold;
[0016] For the adjacent coordinate points, determine a third position identifier based on the horizontal coordinates of the adjacent coordinate points and the number threshold; determine a fourth position identifier based on the vertical coordinates of the adjacent coordinate points and the number threshold;
[0017] Determining whether the first location identifier is the same as the third location identifier, and whether the second location identifier is the same as the fourth location identifier;
[0018] When the first location identifier is the same as the third location identifier, and the second location identifier is the same as the fourth location identifier, it is determined that the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs.
[0019] In a possible implementation, determining the first location identifier based on the horizontal coordinate of the target coordinate point and the number threshold includes:
[0020] Calculating a first ratio of the horizontal coordinate of the target coordinate point to the square root of the number threshold;
[0021] determining a first position identifier based on the first ratio;
[0022] The determining the second position identifier based on the ordinate of the target coordinate point and the number threshold includes:
[0023] Calculating a second ratio of the ordinate of the target coordinate point to the square root of the number threshold;
[0024] A second location identifier is determined based on the second ratio.
[0025] In a possible implementation manner, determining the first location identifier based on the first ratio includes:
[0026] When the first ratio is an integer, determining the first ratio to be the first position identifier;
[0027] When the first ratio is not an integer, the first ratio is rounded down to obtain the first position identifier.
[0028] In a possible implementation, the target coordinate point is sent by the back-end simulation service to the front-end browser in a message format, and the message includes a type, a data length and a coordinate point.
[0029] In a possible implementation, the method further includes:
[0030] When the number of coordinate points in the array reaches a preset value, any coordinate point in the array at a non-initial time is determined as the target coordinate point, and the above steps are executed again to update the array.
[0031] In a possible implementation, the method further includes:
[0032] The array is sent to the front-end browser so that the front-end browser periodically obtains a preset number of coordinate points from the array for drawing.
[0033] In a second aspect, the present application provides a data downsampling processing device, the device comprising:
[0034] A determination unit, used to determine a threshold value of the number of coordinate points accommodated by a single pixel point of the front-end browser;
[0035] An acquisition unit, for acquiring, for the acquired target coordinate point, an adjacent coordinate point on the target coordinate point when the target coordinate point is a coordinate point at a non-initial moment;
[0036] A judging unit, used to judge whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs, by using the number threshold;
[0037] The processing unit is configured to discard the target coordinate point when the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs.
[0038] In a possible implementation, the device further includes: a storage unit, configured to store the target coordinate point in an array including the adjacent coordinate points when the area range to which the target coordinate point belongs is different from the area range to which the adjacent coordinate points belong.
[0039] In a possible implementation, the processing unit is further used to calculate, for any three adjacent coordinate points in the array, a first slope of a line corresponding to a first coordinate point and a second coordinate point, and a second slope of a line corresponding to a third coordinate point and the second coordinate point, the first coordinate point being adjacent to the second coordinate point, and the second coordinate point being adjacent to the third coordinate point; when the first slope is the same as the second slope, the second coordinate point in the array is deleted.
[0040] In a possible implementation, the judgment unit is specifically used to determine, for the target coordinate point, a first position identifier based on the horizontal coordinate of the target coordinate point and the number threshold; determine a second position identifier based on the vertical coordinate of the target coordinate point and the number threshold; determine a third position identifier for the adjacent coordinate point based on the horizontal coordinate of the adjacent coordinate point and the number threshold; determine a fourth position identifier based on the vertical coordinate of the adjacent coordinate point and the number threshold; determine whether the first position identifier is the same as the third position identifier, and whether the second position identifier is the same as the fourth position identifier; when the first position identifier is the same as the third position identifier, and the second position identifier is the same as the fourth position identifier, determine that the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs.
[0041] In a possible implementation, the judgment unit is specifically configured to calculate a first ratio of the horizontal coordinate of the target coordinate point to the square root of the number threshold; and determine a first position identifier based on the first ratio;
[0042] The judgment unit is specifically used to calculate a second ratio of the ordinate of the target coordinate point to the square root of the number threshold; and determine a second position identifier based on the second ratio.
[0043] In a possible implementation, the judgment unit is specifically used to determine the first ratio as the first position identifier when the first ratio is an integer; when the first ratio is not an integer, round down the first ratio to obtain the first position identifier.
[0044] In a possible implementation, the target coordinate point is sent by the back-end simulation service to the front-end browser in a message format, and the message includes a type, a data length and a coordinate point.
[0045] In a possible implementation, the device further includes: an updating unit, which is used to determine any coordinate point in the array at a non-initial moment as the target coordinate point when the number of coordinate points in the array reaches a preset value, re-execute the above steps, and update the array.
[0046] In a possible implementation, the device further includes: a sending unit, configured to send the array to a front-end browser, so that the front-end browser periodically obtains a preset number of coordinate points from the array for drawing.
[0047] In a third aspect, the present application provides a data downsampling processing device, the device comprising: a memory and a processor;
[0048] The memory is used to store relevant program codes;
[0049] The processor is used to call the program code to execute the data downsampling processing method described in any one of the implementation modes of the first aspect above.
[0050] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program is used to execute the data downsampling processing method described in any one of the implementations of the first aspect above.
[0051] It can be seen that this application has the following beneficial effects:
[0052] In the above implementation of the present application, the threshold value of the number of coordinate points accommodated by a single pixel of the front-end browser is first determined, and the downsampling judgment can be made based on the threshold value later. For the acquired target coordinate point, when the target coordinate point is a coordinate point at a non-initial moment, the adjacent adjacent coordinate point on the target coordinate point is acquired. Using the number threshold, it is determined whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs. When the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs, only the original adjacent coordinate point is retained and the target coordinate point is discarded. Through the method provided by the present application, the number of coordinate points that can be accommodated by a single pixel is used to determine whether two adjacent coordinate points belong to the same area range. Since multiple coordinate points within the same pixel are also displayed as only one pixel, it is possible to achieve data downsampling processing while minimizing the impact on the drawing accuracy, so as to reduce the amount of data that the front-end browser needs to draw and ensure the normal display of the page. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. It is obvious that the drawings described below are only some embodiments provided in the present application, and a person skilled in the art can also obtain other drawings based on these drawings.
[0054] Figure 1 A flowchart of a data downsampling processing method provided in an embodiment of the present application;
[0055] Figure 2 A schematic diagram of a data downsampling processing device provided in an embodiment of the present application;
[0056] Figure 3 A schematic diagram of a data downsampling processing device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0057] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. The described embodiments are only exemplary implementation methods of the present application, not all implementation methods. Those skilled in the art can combine the embodiments of the present application to obtain other embodiments without creative work, and these embodiments are also within the scope of protection of the present application.
[0058] In the application scenario of simulation drawing, the data generated by the simulation needs to be sent to the front-end browser, and the browser draws the corresponding chart based on the received coordinate point data. When the simulation engine generates a large amount of coordinate point data and sends it to the front-end browser, the browser needs to draw a large number of dense data points, which can easily cause the browser page display to freeze or even crash.
[0059] Based on this, the embodiment of the present application provides a data downsampling processing method to reduce the amount of data drawn by the front-end browser and ensure the normal display of the page. In the specific implementation, the number threshold of the coordinate points accommodated by a single pixel of the front-end browser is first determined, and the downsampling judgment can be made based on the threshold later. For the acquired target coordinate point, when the target coordinate point is a coordinate point at a non-initial moment, the adjacent adjacent coordinate point on the target coordinate point is acquired. Using the number threshold, it is determined whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs. When the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs, only the original adjacent coordinate point is retained and the target coordinate point is discarded. Through the method provided by the present application, the number of coordinate points that can be accommodated by a single pixel is used to determine whether two adjacent coordinate points belong to the same area range. Since multiple coordinate points in the same pixel are also displayed as only one pixel, the data downsampling processing can be achieved while minimizing the influence on the drawing accuracy to reduce the amount of data that the front-end browser needs to draw and ensure the normal display of the page.
[0060] In order to facilitate the understanding of the technical solution provided by the embodiments of the present application, a detailed introduction will be given below with reference to the accompanying drawings.
[0061] See also Figure 1 , Figure 1 A flowchart of a data downsampling processing method provided in an embodiment of the present application.
[0062] Optionally, the method may be executed by a front-end browser, for example, by a processing device of the front-end browser.
[0063] The method may include the following steps:
[0064] S101: Determine a threshold value of the number of coordinate points that a single pixel of a front-end browser can accommodate.
[0065] When the coordinate points generated by the back-end simulation service are drawn to the front-end browser, each pixel in the display page of the front-end browser may accommodate multiple coordinate points, but only one pixel is displayed on the page. Therefore, the coordinate points can be downsampled using the threshold of the number of coordinate points accommodated by a single pixel to minimize the drawing accuracy of the front-end browser.
[0066] In a possible implementation, the threshold of the number of coordinate points accommodated by a single pixel can be determined by combining the size and resolution of the page displayed by the front-end browser to determine the size corresponding to each pixel, and then determined by combining manual experience. For example, when the display size corresponding to a single pixel is large, the threshold of the number of coordinate points accommodated can be set slightly larger; when the display size corresponding to a single pixel is large, the threshold of the number of coordinate points accommodated can be set slightly larger, for example, it can usually be set to 4 or 9.
[0067] S102: For the acquired target coordinate point, when the target coordinate point is a coordinate point at a non-initial moment, an adjacent coordinate point on the target coordinate point is acquired.
[0068] In the embodiment of the present application, downsampling processing can be performed on two adjacent coordinate points. When the back-end simulation service outputs the coordinate points, they can be first stored in the cache of the front-end browser, and the coordinate points in the cache can be downsampled before being drawn by the front-end browser. The coordinate points output by the back-end simulation service include time information. For example, the horizontal coordinate of the coordinate point can be used to represent time.
[0069] Optionally, the backend emulation service and the frontend browser can communicate via WebSocket, a protocol for full-duplex communication over a single TCP connection that makes data exchange between the client and the server much simpler, allowing the server to actively push data to the client.
[0070] In a possible implementation, in order to reduce the pressure of data transmission and prevent different types of coordinate points from being out of order, the back-end simulation service can transmit the coordinate points in the format of a message. Among them, the message may include a type, a data length, and the coordinate points to be transmitted. The type can be used to indicate the type of the coordinate point, and the data length can be used to indicate the data length of the coordinate point transmitted by the message. For example, the message format can be a TLV message, including Type, Length, and Value. The Type field can indicate the message type, and in the embodiment of the present application, it can be used to indicate the types of different coordinate points. The Length field indicates the message length, and the Value field is often used to store the content of the message, and in the embodiment of the present application, it is used to store the coordinate points.
[0071] Optionally, when the length of the coordinate points included in the message is inconsistent with the data length, packet loss may occur. Therefore, you can wait for the next message with the same coordinate point type, read the coordinate points of the remaining length from the next message, and merge them with the coordinate points in the previous message for processing.
[0072] Furthermore, in order to reduce the pressure of data transmission and prevent data link overload, the backend simulation service can be set to send a message once per second.
[0073] Optionally, when downsampling the coordinate points in the cache, multiple coordinate points of a first preset length can be first obtained for processing, that is, the coordinate points in the cache are processed in batches. For the multiple coordinate points obtained from the cache, the processing device can process them according to the order in which the coordinate points are generated. When the processing device obtains the coordinate point at the initial moment, since the coordinate point is the first coordinate point, there is no need to downsample the coordinate point. The initial coordinate point can be stored in an array later and sent to the front-end browser for chart drawing. When the processing device obtains the coordinate point at a non-initial moment, since the coordinate point is not the first coordinate point, an adjacent adjacent coordinate point on the coordinate point can be obtained. That is, for the target coordinate point obtained by the processing device, when the target coordinate point is a coordinate point at a non-initial moment, an adjacent adjacent coordinate point on the target coordinate point is obtained.
[0074] It should be understood that the adjacent coordinate point is represented as a coordinate point that has not been discarded by downsampling. Therefore, the time corresponding to the adjacent coordinate point and the time corresponding to the target coordinate point may be separated by multiple time units (the time units of the coordinate points output by the back-end simulation service). That is, there may be other coordinate points discarded by downsampling between the target coordinate point and the adjacent coordinate point.
[0075] In one possible implementation, the back-end simulation service may generate multiple coordinate points at the same time, that is, the times corresponding to different coordinate points may be the same. At this time, the adjacent coordinate points of the "previous time" or "next time" can be determined according to the order in which the coordinate points are output by the back-end simulation service. For example, when two adjacent coordinate points are a first coordinate point and a second coordinate point, the time when the first coordinate point and the second coordinate point are generated is the same, but when the back-end simulation service sends the coordinate points to the cache, it sends the first coordinate point first and then the second coordinate point, that is, the first coordinate point is stored in the cache first, and the second coordinate point is stored in the cache later, then the first coordinate point represents the adjacent coordinate point of the second coordinate point at the previous time.
[0076] S103: Using the number threshold, determine whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs.
[0077] Since the number threshold of coordinate points contained in a single pixel is predetermined, the number threshold can be used to determine whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs.
[0078] In a possible implementation, for the target coordinate point, a first position identifier can be determined based on the horizontal coordinate and number threshold of the target coordinate point. Similarly, a second position identifier can be determined based on the vertical coordinate and number threshold of the target coordinate point. That is, the area range to which the target coordinate point belongs is determined based on the first position identifier and the second position identifier. For example, the area range can represent a grid. For adjacent coordinate points, a third position identifier can be determined based on the horizontal coordinate and number threshold of the adjacent coordinate points. A fourth position identifier is determined based on the vertical coordinate and number threshold of the adjacent coordinate points.
[0079] In order to determine whether the target coordinate point and the adjacent coordinate point belong to the same area range, it can be determined whether the first position identifier is the same as the third position identifier, and whether the second position identifier is the same as the fourth position identifier. When the first position identifier is the same as the third position identifier, and the second position identifier is the same as the fourth position identifier, it is determined that the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs.
[0080] When determining the first position identifier of the target coordinate point, it can be achieved in the following manner: calculate the first ratio of the horizontal coordinate of the target coordinate point to the square root of the number threshold, and then determine the first position identifier based on the first ratio. The square root of the number threshold is to simulate and determine a square based on the number threshold. For example, when the number threshold is 4, the square root of the number threshold is 2, that is, determine a square with a side length of 2 as the area range to which the coordinate point belongs.
[0081] In a specific implementation, when the first ratio is an integer, the first ratio can be determined as the first position identifier. When the first ratio is not an integer, the first ratio can be rounded down to obtain the first position identifier. For example, when the first ratio is 2.3, the integer ratio obtained by rounding down is 2, that is, the first position identifier is 2; when the first ratio is a positive number 4, the first position identifier is 4.
[0082] Similarly, when determining the second position identifier of the target coordinate point, it can be achieved in the following manner: calculate the second ratio of the ordinate of the target coordinate point to the square root of the number threshold, and then determine the second position identifier based on the second ratio. In specific implementation, when the second ratio is an integer, the second ratio can be determined as the second position identifier. When the second ratio is not an integer, the second ratio can be rounded down to obtain the second position identifier.
[0083] It should be noted that when the first ratio or the second ratio is not an integer, rounding down the first ratio or the second ratio to determine the first position identifier / second position identifier is only an exemplary description and is not limited to the above implementation. For example, the first ratio or the second ratio may also be rounded up to determine the first position identifier or the second position identifier, so as to ensure that the same processing method is applied to all coordinate points.
[0084] S104: When the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs, the target coordinate point is discarded.
[0085] When the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs, it means that the performance represented by the target coordinate point and the adjacent coordinate point are close. At this time, the target coordinate point can be discarded and only the performance of the original adjacent coordinate point can be retained to achieve downsampling of the data.
[0086] When the area range to which the target coordinate point belongs is different from the area range to which the adjacent coordinate point belongs, it indicates that the coordinate values of the target coordinate point and the adjacent coordinate point differ greatly, which can reflect the performance of the drawn chart, so the target coordinate point can be retained. Optionally, in an embodiment of the present application, an array can be used to store coordinate points for front-end drawing, that is, the target coordinate points that have not been downsampled are stored in an array, and the array is subsequently sent to the front-end browser for page chart drawing. Among them, the array also includes the adjacent coordinate points that were previously retained. When storing the target coordinate points, they can be stored in the time order of the coordinate points, that is, the target coordinate point is stored adjacent to the previous adjacent coordinate point.
[0087] For ease of understanding, a specific application scenario will be introduced below.
[0088] In this application scenario, the horizontal coordinate of the coordinate point can be set to represent time, and the vertical coordinate can represent the coordinate value. Set the threshold value of the number of coordinate points contained in a single pixel to 4. The target coordinate point obtained from the cache is (3, 2), and the adjacent coordinate points of the target coordinate point are (2, 3). The number threshold 4 is used to determine whether the target coordinate point and the adjacent coordinate point belong to the same area. Specifically, for the target coordinate point (2, 3), the first ratio of the horizontal coordinate 2 of the target coordinate point to the square root 2 of the number threshold 4 is calculated to be 1. Since 1 is an integer, the first ratio 1 is determined to be the first position identifier. For the adjacent coordinate point (3, 2), the third ratio of the horizontal coordinate 3 of the adjacent coordinate point to the square root 2 of the number threshold 4 is calculated to be 1.5. Since 1.5 is not an integer, 1.5 is rounded down to 1, that is, the third position identifier is 1. It can be seen that the first position identifier of the target coordinate point is the same as the third position identifier of the adjacent coordinate point. For the target coordinate point (2, 3), the second ratio of the ordinate 3 of the target coordinate point to the square root 2 of the number threshold 4 is calculated, which is 1.5. Since 1.5 is not an integer, 1.5 is rounded down to 1, that is, the second position identifier is 1. For the adjacent coordinate point (3, 2), the fourth ratio of the ordinate 2 of the adjacent coordinate point to the square root 2 of the number threshold 4 is calculated, which is 1. Since 1 is an integer, the fourth ratio 1 is determined to be the fourth position identifier. It can be known that the second position identifier of the target coordinate point is the same as the fourth position identifier of the adjacent coordinate point. In other words, it can be determined that the target coordinate point and the adjacent coordinate point belong to the same area range, and the target coordinate point is discarded.
[0089] After determining the coordinate points stored in the array by the above method, when the number of coordinate points in the array is large, the coordinate points in the data can be further downsampled, and then the downsampled array is sent to the front-end browser to reduce the coordinate points that need to be drawn.
[0090] In a possible implementation, the coordinate points in the array are stored in the order of generation, and any three adjacent coordinate points in the array are represented as the first coordinate point, the second coordinate point, and the third coordinate point, respectively, wherein the first coordinate point is adjacent to the second coordinate point, and the second coordinate point is adjacent to the third coordinate point, that is, the second coordinate point is the coordinate point located between the first coordinate point and the third coordinate point. The first slope of the line corresponding to the first coordinate point and the second coordinate point, and the second slope of the line corresponding to the third coordinate point and the second coordinate point are calculated. When the first slope is the same as the second slope, it indicates that the three coordinate points are collinear, that is, the second coordinate point in the middle is located on the line connecting the first coordinate point and the third coordinate point, and the second coordinate point in the array can be deleted at this time.
[0091] Specifically, for three adjacent coordinate points, namely the first coordinate point (x1, y1), the second coordinate point (x2, y2) and the third coordinate point (x3, y3), the first slope of the line connecting the first coordinate point and the second coordinate point can be expressed as k1=(y2-y1) / (x2-x1); the slope of the line connecting the third coordinate point and the second coordinate point can be expressed as k2=(y3-y2) / (x3-x2); when (y2-y1) / (x2-x1)=(y3-y2) / (x3-x2), it indicates that the three coordinate points are collinear, that is, the second coordinate point in the middle is located on the line connecting the first coordinate point and the third coordinate point, and the second coordinate point in the array can be deleted at this time.
[0092] The following is a code snippet to illustrate the above implementation process. In this scenario, a new result array can be created to store the coordinate points left after downsampling.
[0093] 1. Define a result array (optimizedPoints) to store the coordinate points after this downsampling process;
[0094] 2. Put the first coordinate of the array to be processed into the result array first;
[0095] 3. Loop the length of the array to be processed - 2 times;
[0096] 4. In the loop, the slopes of every two adjacent coordinate points are calculated in sequence. If the two slopes are the same, the middle coordinate point is discarded. If they are different, the coordinates are added to the result array. The loop stops until the last coordinate point of the array to be processed;
[0097] 5. Add the last coordinate point of the data to be processed directly to the result array.
[0098] Part of the code is:
[0099]
[0100]
[0101] After the coordinate points are downsampled based on the method provided in the above embodiment, the front-end browser can draw a chart according to the coordinate points in the array. Since the backing simulation service will also generate coordinate points during the chart drawing process, the front-end browser also needs to add the newly generated coordinate points in the array to the page. If the number of coordinate points in the array is large, that is, the number of coordinate points in the array meets the preset value, at this time, the above-mentioned downsampling process can also be performed for any coordinate point in the array. The coordinate point of the array is determined as the target coordinate point in the above embodiment, and it is determined whether the target coordinate point is downsampled. After the downsampling process, it is also possible to determine whether any three adjacent points are collinear in the processed array, and downsample the middle coordinate point. The specific implementation process can be referred to the above method embodiment, which will not be introduced here.
[0102] It should be noted that when judging whether the number of coordinate points in the array meets the preset value, the embodiment of the present application does not limit the specific value of the preset value, and can be introduced in combination with actual demand scenarios. For example, the preset value can be set to a multiple of 10,000, that is, when the number of coordinate points in the array reaches 10,000, or reaches 20,000, the downsampling process of the above embodiment is re-executed to update the coordinate points in the array.
[0103] In one possible implementation, after the array is sent to the front-end browser, in order to prevent the page from being stuck due to excessive number of coordinate points drawn at a single time, the front-end browser can periodically obtain a preset number of coordinate points from the array for drawing, that is, obtain a preset number of coordinate points for drawing at fixed intervals to ensure normal drawing and display of the page.
[0104] Through the method provided in the embodiment of the present application, the number of coordinate points that a single pixel can accommodate is used to determine whether two adjacent coordinate points belong to the same area. Since multiple coordinate points within the same pixel are only displayed as one pixel, data downsampling can be achieved without affecting the drawing performance, so as to reduce the amount of data that the front-end browser needs to draw and ensure the normal display of the page.
[0105] Based on the above method embodiment, the present application embodiment also provides a data downsampling processing device. Figure 2 , which is a schematic diagram of a data downsampling processing device provided in an embodiment of the present application.
[0106] The device 200 comprises:
[0107] The determination unit 201 is used to determine the threshold value of the number of coordinate points contained in a single pixel point of the front-end browser;
[0108] An acquiring unit 202 is configured to acquire, for the acquired target coordinate point, an adjacent coordinate point on the target coordinate point when the target coordinate point is a coordinate point at a non-initial moment;
[0109] A judging unit 203 is used to judge whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs by using the number threshold;
[0110] The processing unit 204 is configured to discard the target coordinate point when the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs.
[0111] In a possible implementation, the device further includes: a storage unit, configured to store the target coordinate point in an array including the adjacent coordinate points when the area range to which the target coordinate point belongs is different from the area range to which the adjacent coordinate points belong.
[0112] In a possible implementation, the processing unit 204 is further used to calculate, for any three adjacent coordinate points in the array, a first slope of a line corresponding to a first coordinate point and a second coordinate point, and a second slope of a line corresponding to a third coordinate point and the second coordinate point, the first coordinate point being adjacent to the second coordinate point, and the second coordinate point being adjacent to the third coordinate point; when the first slope is the same as the second slope, the second coordinate point in the array is deleted.
[0113] In a possible implementation, the judgment unit 203 is specifically used to determine, for the target coordinate point, a first position identifier based on the horizontal coordinate of the target coordinate point and the number threshold; determine a second position identifier based on the vertical coordinate of the target coordinate point and the number threshold; determine a third position identifier for the adjacent coordinate point based on the horizontal coordinate of the adjacent coordinate point and the number threshold; determine a fourth position identifier based on the vertical coordinate of the adjacent coordinate point and the number threshold; determine whether the first position identifier is the same as the third position identifier, and whether the second position identifier is the same as the fourth position identifier; when the first position identifier is the same as the third position identifier, and the second position identifier is the same as the fourth position identifier, determine that the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs.
[0114] In a possible implementation, the judgment unit 203 is specifically configured to calculate a first ratio of the horizontal coordinate of the target coordinate point to the square root of the number threshold; and determine a first position identifier based on the first ratio;
[0115] The judgment unit 203 is specifically configured to calculate a second ratio of the ordinate of the target coordinate point to the square root of the number threshold; and determine a second position identifier based on the second ratio.
[0116] In a possible implementation, the judgment unit 203 is specifically configured to determine that the first ratio is the first position identifier when the first ratio is an integer; and to round down the first ratio to obtain the first position identifier when the first ratio is not an integer.
[0117] In a possible implementation, the target coordinate point is sent by the back-end simulation service to the front-end browser in a message format, and the message includes a type, a data length and a coordinate point.
[0118] In a possible implementation, the device further includes: an updating unit, which is used to determine any coordinate point in the array at a non-initial moment as the target coordinate point when the number of coordinate points in the array reaches a preset value, re-execute the above steps, and update the array.
[0119] In a possible implementation, the device further includes: a sending unit, configured to send the array to a front-end browser, so that the front-end browser periodically obtains a preset number of coordinate points from the array for drawing.
[0120] Based on the above method embodiment and device embodiment, the present application embodiment further provides a data downsampling processing device, which will be described below in conjunction with the accompanying drawings.
[0121] See also Figure 3 , Figure 3 A schematic diagram of a data downsampling processing device provided in an embodiment of the present application.
[0122] The device 300 includes: a memory 301 and a processor 302;
[0123] The memory 301 is used to store relevant program codes;
[0124] The processor 302 is used to call the program code to execute the data downsampling processing method described in the above method embodiment;
[0125] The method comprises:
[0126] Determine the threshold value of the number of coordinate points that a single pixel of the front-end browser can accommodate;
[0127] For the acquired target coordinate point, when the target coordinate point is a coordinate point at a non-initial moment, an adjacent coordinate point on the target coordinate point is acquired;
[0128] Using the number threshold, determining whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs;
[0129] When the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs, the target coordinate point is discarded.
[0130] In a possible implementation, the method further includes:
[0131] When the area range to which the target coordinate point belongs is different from the area range to which the adjacent coordinate points belong, the target coordinate point is stored in an array, and the array includes the adjacent coordinate points.
[0132] In a possible implementation, the method further includes:
[0133] For any three adjacent coordinate points in the array, calculate a first slope of a line corresponding to a first coordinate point and a second coordinate point, and a second slope of a line corresponding to a third coordinate point and the second coordinate point, wherein the first coordinate point is adjacent to the second coordinate point, and the second coordinate point is adjacent to the third coordinate point;
[0134] When the first slope is the same as the second slope, the second coordinate point in the array is deleted.
[0135] In a possible implementation, the using the number threshold to determine whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs includes:
[0136] For the target coordinate point, determine a first position identifier based on the horizontal coordinate of the target coordinate point and the number threshold; determine a second position identifier based on the vertical coordinate of the target coordinate point and the number threshold;
[0137] For the adjacent coordinate points, determine a third position identifier based on the horizontal coordinates of the adjacent coordinate points and the number threshold; determine a fourth position identifier based on the vertical coordinates of the adjacent coordinate points and the number threshold;
[0138] Determining whether the first location identifier is the same as the third location identifier, and whether the second location identifier is the same as the fourth location identifier;
[0139] When the first location identifier is the same as the third location identifier, and the second location identifier is the same as the fourth location identifier, it is determined that the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs.
[0140] In a possible implementation, determining the first location identifier based on the horizontal coordinate of the target coordinate point and the number threshold includes:
[0141] Calculating a first ratio of the horizontal coordinate of the target coordinate point to the square root of the number threshold;
[0142] determining a first position identifier based on the first ratio;
[0143] The determining the second position identifier based on the ordinate of the target coordinate point and the number threshold includes:
[0144] Calculating a second ratio of the ordinate of the target coordinate point to the square root of the number threshold;
[0145] A second location identifier is determined based on the second ratio.
[0146] In a possible implementation manner, determining the first location identifier based on the first ratio includes:
[0147] When the first ratio is an integer, determining the first ratio to be the first position identifier;
[0148] When the first ratio is not an integer, the first ratio is rounded down to obtain the first position identifier.
[0149] In a possible implementation, the target coordinate point is sent by the back-end simulation service to the front-end browser in a message format, and the message includes a type, a data length and a coordinate point.
[0150] In a possible implementation, the method further includes:
[0151] When the number of coordinate points in the array reaches a preset value, any coordinate point in the array at a non-initial time is determined as the target coordinate point, and the above steps are executed again to update the array.
[0152] In a possible implementation, the method further includes:
[0153] The array is sent to the front-end browser so that the front-end browser periodically obtains a preset number of coordinate points from the array for drawing.
[0154] In addition, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium is used to store a computer program, and the computer program is used to execute the data downsampling processing method described in the above method embodiment.
[0155] It should be noted that the technical features of the higher-level means provided in the embodiments of the present application are clear to those skilled in the art, and the problems to be solved by the higher-level means are also clear. The means for obtaining the corresponding features can be selected by those skilled in the art according to specific implementation requirements. The means provided in this application should not be regarded as a limitation on the solution or as the only means of implementation.
[0156] It should be noted that the various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same and similar parts between the various embodiments can refer to each other. In particular, for the system or device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can refer to the partial description of the method embodiment. The device embodiment described above is only exemplary, in which the units or modules described as separate components may or may not be physically separated, and the components displayed as units or modules may or may not be physical modules, that is, they may be located in one place, or they may be distributed on multiple network units, and some or all of the units or modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative work.
[0157] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the method, device and equipment etc. of various embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or the flowchart, and the combination of the boxes in the block diagram and / or the flowchart can be implemented with a dedicated hardware-based system that performs the specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0158] It should be understood that in the present application, "at least one (item)" means one or more, and "plurality" means two or more. "And / or" is used to describe the association relationship of associated objects, indicating that three relationships may exist. For example, "A and / or B" can mean: only A exists, only B exists, and A and B exist at the same time, where A and B can be singular or plural. The character " / " generally indicates that the objects associated before and after are in an "or" relationship. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, at least one of a, b or c can mean: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, c can be single or multiple.
[0159] It should also be noted that, in this application, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the statement "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0160] The steps of the method or algorithm described in conjunction with the embodiments disclosed in this application can be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module can be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
[0161] The above description of the disclosed embodiments enables professionals and technicians in the field to implement or use the present application. Various modifications to these embodiments will be apparent to professionals and technicians in the field, and the general principles defined in this application can be implemented in other embodiments without departing from the spirit or scope of the present application. Therefore, the present application will not be limited to the embodiments shown in the present application, but will conform to the widest range consistent with the principles and novel features disclosed in the present application.
Claims
1. A data downsampling processing method, characterized in that: The method comprises: Determine the threshold value of the number of coordinate points that a single pixel of the front-end browser can accommodate; For the acquired target coordinate point, when the target coordinate point is a coordinate point at a non-initial moment, an adjacent coordinate point on the target coordinate point is acquired; Using the number threshold, determining whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs; When the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs, the target coordinate point is discarded.
2. The method according to claim 1, characterized in that The method further comprises: When the area range to which the target coordinate point belongs is different from the area range to which the adjacent coordinate points belong, the target coordinate point is stored in an array, and the array includes the adjacent coordinate points.
3. The method according to claim 2, characterized in that The method further comprises: For any three adjacent coordinate points in the array, calculate a first slope of a line corresponding to a first coordinate point and a second coordinate point, and a second slope of a line corresponding to a third coordinate point and the second coordinate point, wherein the first coordinate point is adjacent to the second coordinate point, and the second coordinate point is adjacent to the third coordinate point; When the first slope is the same as the second slope, the second coordinate point in the array is deleted.
4. The method according to claim 1, characterized in that: The using the number threshold to judge whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs includes: For the target coordinate point, determine a first position identifier based on the horizontal coordinate of the target coordinate point and the number threshold; determine a second position identifier based on the vertical coordinate of the target coordinate point and the number threshold; For the adjacent coordinate points, determine a third position identifier based on the horizontal coordinates of the adjacent coordinate points and the number threshold; determine a fourth position identifier based on the vertical coordinates of the adjacent coordinate points and the number threshold; Determine whether the first location identifier is the same as the third location identifier, and whether the second location identifier is the same as the fourth location identifier; When the first location identifier is the same as the third location identifier, and the second location identifier is the same as the fourth location identifier, it is determined that the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs.
5. The method according to claim 4, characterized in that The determining of the first position identifier based on the horizontal coordinate of the target coordinate point and the number threshold includes: Calculating a first ratio of the abscissa of the target coordinate point to the square root of the number threshold; determining a first position identifier based on the first ratio; The determining of the second position identifier based on the ordinate of the target coordinate point and the number threshold comprises: Calculating a second ratio of the ordinate of the target coordinate point to the square root of the number threshold; A second location identifier is determined based on the second ratio.
6. The method according to claim 5, characterized in that The determining a first position identifier based on the first ratio includes: When the first ratio is an integer, determining the first ratio to be the first position identifier; When the first ratio is not an integer, the first ratio is rounded down to obtain the first position identifier.
7. The method according to claim 1, characterized in that The target coordinate point is sent by the back-end simulation service to the front-end browser in the format of a message, and the message includes a type, a data length and a coordinate point.
8. The method according to claim 2 or 3, characterized in that: The method further comprises: When the number of coordinate points in the array reaches a preset value, any coordinate point in the array at a non-initial time is determined as the target coordinate point, and the above steps are re-executed to update the array.
9. The method according to claim 8, characterized in that The method further comprises: The array is sent to the front-end browser so that the front-end browser periodically obtains a preset number of coordinate points from the array for drawing.
10. A data downsampling processing device, characterized in that: The device comprises: A determination unit, used to determine a threshold value of the number of coordinate points accommodated by a single pixel point of the front-end browser; An acquisition unit, for acquiring, for the acquired target coordinate point, an adjacent coordinate point on the target coordinate point when the target coordinate point is a coordinate point at a non-initial moment; A judging unit, used to judge whether the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs, by using the number threshold; The processing unit is configured to discard the target coordinate point when the area range to which the target coordinate point belongs is the same as the area range to which the adjacent coordinate point belongs.
Citation Information
Patent Citations
Drawing method and device
CN101976448A
High density multi-view image display system and method with active sub-pixel rendering
CN102056003A
Data processing method and device, electronic equipment and storage medium
CN115546346A
Curve drawing method, device and equipment and readable storage medium
CN116863030A
System, method and program for computer graphics rendering
US20010030650A1
